Don't limit '*' to a single 128KB buffer.

git-svn: trunk@457
This commit is contained in:
Tomasz Kojm 2004-03-31 07:15:00 +00:00
parent 1bfbedd487
commit b5b62ca7f1
5 changed files with 39 additions and 11 deletions

View file

@ -1,3 +1,7 @@
Wed Mar 31 09:25:25 CEST 2004 (tk)
----------------------------------
* libclamav: matcher: don't limit '*' to a single 128KB buffer
Tue Mar 30 23:57:33 BST 2004 (njh)
----------------------------------
* libclamav/mbox.c: Better handling of multipart within multipart messages

View file

@ -193,21 +193,25 @@ void cl_freetrie(struct cl_node *root)
free(root);
}
int cl_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root)
int cli_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root, int *pcnt)
{
struct cl_node *current;
struct cli_patt *pt;
int position, *partcnt;
int position, *partcnt, extpartcnt = 0;
unsigned int i;
current = (struct cl_node *) root;
if ((partcnt = (int *) cli_calloc(root->partsigs + 1, sizeof(int))) == NULL) {
cli_dbgmsg("cl_scanbuff(): unable to calloc(%d, %d)\n", root->partsigs + 1, sizeof(int));
return CL_EMEM;
if(pcnt) {
partcnt = pcnt;
extpartcnt = 1;
} else {
if((partcnt = (int *) cli_calloc(root->partsigs + 1, sizeof(int))) == NULL) {
cli_dbgmsg("cl_scanbuff(): unable to calloc(%d, %d)\n", root->partsigs + 1, sizeof(int));
return CL_EMEM;
}
}
for(i = 0; i < length; i++) {
current = current->trans[(unsigned char) buffer[i] & 0xff];
@ -222,14 +226,16 @@ int cl_scanbuff(const char *buffer, unsigned int length, const char **virname, c
if(++partcnt[pt->sigid] == pt->parts) { /* last */
if(virname)
*virname = pt->virname;
free(partcnt);
if(!extpartcnt)
free(partcnt);
return CL_VIRUS;
}
}
} else { /* old type signature */
if(virname)
*virname = pt->virname;
free(partcnt);
if(!extpartcnt)
free(partcnt);
return CL_VIRUS;
}
}
@ -241,10 +247,17 @@ int cl_scanbuff(const char *buffer, unsigned int length, const char **virname, c
}
}
free(partcnt);
if(!extpartcnt)
free(partcnt);
return CL_CLEAN;
}
int cl_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root)
{
return cli_scanbuff(buffer, length, virname, root, NULL);
}
int cli_findpos(const char *buffer, int offset, int length, const struct cli_patt *pattern)
{
int bufferpos = offset + CL_MIN_LENGTH;

View file

@ -31,5 +31,6 @@ struct nodelist *cli_bfsadd(struct nodelist *bfs, struct cl_node *n);
void cli_failtrans(struct cl_node *root);
void cli_fasttrie(struct cl_node *n, struct cl_node *root);
int cli_findpos(const char *buffer, int offset, int length, const struct cli_patt *pattern);
int cli_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root, int *pcnt);
#endif

View file

@ -225,6 +225,7 @@ void *cli_malloc(size_t size)
if(!alloc) {
cli_errmsg("cli_malloc(): Can't allocate memory (%d bytes).\n", size);
perror("malloc_problem");
/* _exit(1); */
return NULL;
} else return alloc;
}
@ -238,6 +239,7 @@ void *cli_calloc(size_t nmemb, size_t size)
if(!alloc) {
cli_errmsg("cli_calloc(): Can't allocate memory (%d bytes).\n", nmemb * size);
perror("calloc_problem");
/* _exit(1); */
return NULL;
} else return alloc;
}

View file

@ -113,7 +113,7 @@ static int cli_scandesc(int desc, const char **virname, long int *scanned, const
cl_node *root)
{
char *buffer, *buff, *endbl, *pt;
int bytes, buffsize, length, ret;
int bytes, buffsize, length, ret, *partcnt;
/* prepare the buffer */
buffsize = root->maxpatlen + SCANBUFF;
@ -122,6 +122,12 @@ cl_node *root)
return CL_EMEM;
}
if((partcnt = (int *) cli_calloc(root->partsigs + 1, sizeof(int))) == NULL) {
cli_dbgmsg("cl_scandesc(): unable to calloc(%d, %d)\n", root->partsigs + 1, sizeof(int));
free(buffer);
return CL_EMEM;
}
buff = buffer;
buff += root->maxpatlen; /* pointer to read data block */
endbl = buff + SCANBUFF - root->maxpatlen; /* pointer to the last block
@ -138,8 +144,9 @@ cl_node *root)
if(bytes < SCANBUFF)
length -= SCANBUFF - bytes;
if((ret = cl_scanbuff(pt, length, virname, root)) != CL_CLEAN) {
if((ret = cli_scanbuff(pt, length, virname, root, partcnt)) != CL_CLEAN) {
free(buffer);
free(partcnt);
return ret;
}
@ -152,6 +159,7 @@ cl_node *root)
}
free(buffer);
free(partcnt);
return CL_CLEAN;
}