git-svn: trunk@3616
aCaB authored on 2008/02/12 05:19:20... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Mon Feb 11 21:04:30 CET 2008 (acab) |
|
2 |
+----------------------------------- |
|
3 |
+ * libclamav: more limit updates, more to come |
|
4 |
+ |
|
1 | 5 |
Mon Feb 11 19:15:16 CET 2008 (tk) |
2 | 6 |
--------------------------------- |
3 | 7 |
* libclamav: mail: scan text attachments and decoded base64 bodies also with |
... | ... |
@@ -65,11 +65,12 @@ static char const rcsid[] = "$Id: blob.c,v 1.64 2007/02/12 22:25:14 njh Exp $"; |
65 | 65 |
#include <windows.h> |
66 | 66 |
#endif |
67 | 67 |
|
68 |
-#define MAX_SCAN_SIZE 20*1024 /* |
|
69 |
- * The performance benefit of scanning |
|
70 |
- * early disappears on medium and |
|
71 |
- * large sized files |
|
72 |
- */ |
|
68 |
+/* Scehduled for rewite in 0.94 (bb#804). Disabling for now */ |
|
69 |
+/* #define MAX_SCAN_SIZE 20*1024 /\* */ |
|
70 |
+/* * The performance benefit of scanning */ |
|
71 |
+/* * early disappears on medium and */ |
|
72 |
+/* * large sized files */ |
|
73 |
+/* *\/ */ |
|
73 | 74 |
|
74 | 75 |
static const char *blobGetFilename(const blob *b); |
75 | 76 |
|
... | ... |
@@ -618,9 +619,8 @@ fileblobAddData(fileblob *fb, const unsigned char *data, size_t len) |
618 | 618 |
if(ctx) { |
619 | 619 |
int do_scan = 1; |
620 | 620 |
|
621 |
- if(ctx->limits && ctx->limits->maxfilesize) /* FIXMELIMITS */ |
|
622 |
- if(fb->bytes_scanned >= ctx->limits->maxfilesize) |
|
623 |
- do_scan = 0; |
|
621 |
+ if(cli_checklimits("fileblobAddData", ctx, fb->bytes_scanned, 0, 0)!=CL_CLEAN) |
|
622 |
+ do_scan = 0; |
|
624 | 623 |
|
625 | 624 |
if(fb->bytes_scanned > MAX_SCAN_SIZE) |
626 | 625 |
do_scan = 0; |
... | ... |
@@ -116,8 +116,4 @@ int cli_chm_open(int fd, const char *dirname, chm_metadata_t *metadata); |
116 | 116 |
int cli_chm_prepare_file(int fd, char *dirname, chm_metadata_t *metadata); |
117 | 117 |
int cli_chm_extract_file(int fd, char *dirname, chm_metadata_t *metadata); |
118 | 118 |
void cli_chm_close(chm_metadata_t *metadata); |
119 |
-int cli_chm_open(int fd, const char *dirname, chm_metadata_t *metadata); |
|
120 |
-void cli_chm_close(chm_metadata_t *metadata); |
|
121 |
-int cli_chm_extract_file(int fd, char *dirname, chm_metadata_t *metadata); |
|
122 |
-int cli_chm_prepare_file(int fd, char *dirname, chm_metadata_t *metadata); |
|
123 | 119 |
#endif |
... | ... |
@@ -53,12 +53,14 @@ int cli_scanbuff(const unsigned char *buffer, uint32_t length, const char **virn |
53 | 53 |
struct cli_ac_data mdata; |
54 | 54 |
struct cli_matcher *groot, *troot = NULL; |
55 | 55 |
|
56 |
- |
|
57 | 56 |
if(!engine) { |
58 | 57 |
cli_errmsg("cli_scanbuff: engine == NULL\n"); |
59 | 58 |
return CL_ENULLARG; |
60 | 59 |
} |
61 | 60 |
|
61 |
+ if(cli_updatelimits(ctx, length)!=CL_CLEAN) |
|
62 |
+ return CL_CLEAN; |
|
63 |
+ |
|
62 | 64 |
groot = engine->root[0]; /* generic signatures */ |
63 | 65 |
|
64 | 66 |
if(ftype) { |
... | ... |
@@ -2010,9 +2010,9 @@ parseEmailBody(message *messageIn, text *textIn, mbox_ctx *mctx, unsigned int re |
2010 | 2010 |
cli_dbgmsg("in parseEmailBody, %u files saved so far\n", |
2011 | 2011 |
mctx->files); |
2012 | 2012 |
|
2013 |
- if(limits) { /* FIXMELIMITS */ |
|
2013 |
+ if(limits) { /* FIXMELIMITS: this should be better integrated */ |
|
2014 | 2014 |
if(limits->maxreclevel) { |
2015 |
- const cli_ctx *ctx = mctx->ctx; /* needed for BLOCKMAX :-( */ |
|
2015 |
+ const cli_ctx *ctx = mctx->ctx; |
|
2016 | 2016 |
|
2017 | 2017 |
/* |
2018 | 2018 |
* This is approximate |
... | ... |
@@ -189,7 +189,6 @@ cli_pdf(const char *dir, int desc, const cli_ctx *ctx) |
189 | 189 |
bytesleft -= xreflength; |
190 | 190 |
*/ |
191 | 191 |
|
192 |
- rc = CL_CLEAN; |
|
193 | 192 |
files = 0; |
194 | 193 |
|
195 | 194 |
/* |
... | ... |
@@ -430,13 +429,20 @@ cli_pdf(const char *dir, int desc, const cli_ctx *ctx) |
430 | 430 |
#endif |
431 | 431 |
|
432 | 432 |
if(is_ascii85decode) { |
433 |
- unsigned char *tmpbuf = cli_malloc(calculated_streamlen * 5); |
|
434 |
- int ret; |
|
433 |
+ unsigned char *tmpbuf; = cli_malloc(calculated_streamlen * 5); |
|
434 |
+ int ret = cli_checklimits("cli_pdf", ctx, calculated_streamlen * 5, calculated_streamlen, 0); |
|
435 |
+ |
|
436 |
+ if(ret != CL_CLEAN) { |
|
437 |
+ close(fout); |
|
438 |
+ unlink(fullname); |
|
439 |
+ continue; |
|
440 |
+ } |
|
441 |
+ |
|
442 |
+ tmpbuf = cli_malloc(calculated_streamlen * 5); |
|
435 | 443 |
|
436 | 444 |
if(tmpbuf == NULL) { |
437 | 445 |
close(fout); |
438 | 446 |
unlink(fullname); |
439 |
- rc = CL_EMEM; |
|
440 | 447 |
continue; |
441 | 448 |
} |
442 | 449 |
|
... | ... |
@@ -446,7 +452,6 @@ cli_pdf(const char *dir, int desc, const cli_ctx *ctx) |
446 | 446 |
free(tmpbuf); |
447 | 447 |
close(fout); |
448 | 448 |
unlink(fullname); |
449 |
- rc = CL_CLEAN; |
|
450 | 449 |
continue; |
451 | 450 |
} |
452 | 451 |
if(ret) { |
... | ... |
@@ -459,7 +464,6 @@ cli_pdf(const char *dir, int desc, const cli_ctx *ctx) |
459 | 459 |
free(tmpbuf); |
460 | 460 |
close(fout); |
461 | 461 |
unlink(fullname); |
462 |
- rc = CL_EMEM; |
|
463 | 462 |
continue; |
464 | 463 |
} |
465 | 464 |
tmpbuf = t; |
... | ... |
@@ -467,16 +471,17 @@ cli_pdf(const char *dir, int desc, const cli_ctx *ctx) |
467 | 467 |
* Note that it will probably be both |
468 | 468 |
* ascii85encoded and flateencoded |
469 | 469 |
*/ |
470 |
+ |
|
470 | 471 |
if(is_flatedecode) |
471 | 472 |
rc = try_flatedecode((unsigned char *)tmpbuf, real_streamlen, real_streamlen, fout, ctx); |
472 | 473 |
else |
473 | 474 |
cli_writen(fout, (const char *)streamstart, real_streamlen); |
474 | 475 |
} |
475 | 476 |
free(tmpbuf); |
476 |
- } else if(is_flatedecode) |
|
477 |
+ } else if(is_flatedecode) { |
|
477 | 478 |
rc = try_flatedecode((unsigned char *)streamstart, real_streamlen, calculated_streamlen, fout, ctx); |
478 | 479 |
|
479 |
- else { |
|
480 |
+ } else { |
|
480 | 481 |
cli_dbgmsg("cli_pdf: writing %lu bytes from the stream\n", |
481 | 482 |
(unsigned long)real_streamlen); |
482 | 483 |
cli_writen(fout, (const char *)streamstart, real_streamlen); |
... | ... |
@@ -508,9 +513,9 @@ cli_pdf(const char *dir, int desc, const cli_ctx *ctx) |
508 | 508 |
static int |
509 | 509 |
try_flatedecode(unsigned char *buf, off_t real_len, off_t calculated_len, int fout, const cli_ctx *ctx) |
510 | 510 |
{ |
511 |
- int ret = flatedecode(buf, real_len, fout, ctx); |
|
511 |
+ int ret = cli_checklimits("cli_pdf", ctx, real_len, 0, 0); |
|
512 | 512 |
|
513 |
- if(ret == CL_SUCCESS) |
|
513 |
+ if (ret==CL_CLEAN && flatedecode(buf, real_len, fout, ctx) == CL_SUCCESS) |
|
514 | 514 |
return CL_SUCCESS; |
515 | 515 |
|
516 | 516 |
if(real_len == calculated_len) { |
... | ... |
@@ -521,6 +526,9 @@ try_flatedecode(unsigned char *buf, off_t real_len, off_t calculated_len, int fo |
521 | 521 |
return CL_CLEAN; |
522 | 522 |
} |
523 | 523 |
|
524 |
+ if(cli_checklimits("cli_pdf", ctx, calculated_len, 0, 0)!=CL_CLEAN) |
|
525 |
+ return CL_CLEAN; |
|
526 |
+ |
|
524 | 527 |
ret = flatedecode(buf, calculated_len, fout, ctx); |
525 | 528 |
if(ret == CL_SUCCESS) |
526 | 529 |
return CL_SUCCESS; |
... | ... |
@@ -605,7 +613,6 @@ flatedecode(unsigned char *buf, off_t len, int fout, const cli_ctx *ctx) |
605 | 605 |
nbytes += written; |
606 | 606 |
|
607 | 607 |
if((ret=cli_checklimits("cli_pdf", ctx, nbytes, 0, 0))!=CL_CLEAN) { |
608 |
- /* FIXMELIMITS */ |
|
609 | 608 |
inflateEnd(&stream); |
610 | 609 |
return ret; |
611 | 610 |
} |
... | ... |
@@ -230,7 +230,7 @@ static int cli_unrar_scanmetadata(int desc, unrar_metadata_t *metadata, cli_ctx |
230 | 230 |
if(mdata->fileno && mdata->fileno != files) |
231 | 231 |
continue; |
232 | 232 |
|
233 |
- if(mdata->maxdepth && ctx->recursion > mdata->maxdepth) /* FIXMELIMITS */ |
|
233 |
+ if(mdata->maxdepth && ctx->recursion > mdata->maxdepth) |
|
234 | 234 |
continue; |
235 | 235 |
|
236 | 236 |
/* TODO add support for regex */ |
... | ... |
@@ -401,7 +401,6 @@ static int cli_scanarj(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c |
401 | 401 |
break; |
402 | 402 |
} |
403 | 403 |
if ((ret = cli_checklimits("ARJ", ctx, metadata.orig_size, metadata.comp_size, 0))!=CL_CLEAN) { |
404 |
- /* FIXMELIMITS: is this correct, shall I free something? */ |
|
405 | 404 |
ret = CL_SUCCESS; |
406 | 405 |
continue; |
407 | 406 |
} |
... | ... |
@@ -372,7 +372,7 @@ int unspin(char *src, int ssize, struct cli_exe_section *sections, int sectcnt, |
372 | 372 |
bitmap = cli_readint32(ep+0x3061); |
373 | 373 |
bitman = bitmap; |
374 | 374 |
|
375 |
- /* FIXMELIMITS */ |
|
375 |
+ /* FIXMELIMITS: possibly rewrite to use the limits api */ |
|
376 | 376 |
if(ctx->limits && ctx->limits->maxfilesize) { |
377 | 377 |
unsigned long int filesize = 0; |
378 | 378 |
|