git-svn: trunk@3505
aCaB authored on 2008/01/18 06:06:35... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Thu Jan 17 21:38:58 CET 2008 (acab) |
|
2 |
+----------------------------------- |
|
3 |
+ * libclamav/nsis: use mmap if avail, prevent cli_malloc() spam if unavail, |
|
4 |
+ nsis_st reordered, close bb#738 |
|
5 |
+ |
|
1 | 6 |
Thu Jan 17 10:15:59 EST 2008 (tk) |
2 | 7 |
--------------------------------- |
3 | 8 |
* libclamav: disable some debug spam |
... | ... |
@@ -29,6 +29,12 @@ |
29 | 29 |
#include <unistd.h> |
30 | 30 |
#endif |
31 | 31 |
|
32 |
+#if HAVE_MMAP |
|
33 |
+#ifdef HAVE_SYS_MMAN_H |
|
34 |
+#include <sys/mman.h> |
|
35 |
+#endif |
|
36 |
+#endif |
|
37 |
+ |
|
32 | 38 |
#include "others.h" |
33 | 39 |
#include "cltypes.h" |
34 | 40 |
#include "nsis_bzlib.h" |
... | ... |
@@ -56,10 +62,15 @@ struct nsis_st { |
56 | 56 |
int ifd; |
57 | 57 |
int ofd; |
58 | 58 |
off_t off; |
59 |
+ off_t fullsz; |
|
59 | 60 |
char *dir; |
60 | 61 |
uint32_t asz; |
61 | 62 |
uint32_t hsz; |
62 | 63 |
uint32_t fno; |
64 |
+ uint8_t comp; |
|
65 |
+ uint8_t solid; |
|
66 |
+ uint8_t freecomp; |
|
67 |
+ uint8_t eof; |
|
63 | 68 |
struct { |
64 | 69 |
uint32_t avail_in; |
65 | 70 |
unsigned char *next_in; |
... | ... |
@@ -70,10 +81,6 @@ struct nsis_st { |
70 | 70 |
CLI_LZMA lz; |
71 | 71 |
z_stream z; |
72 | 72 |
unsigned char *freeme; |
73 |
- uint8_t comp; |
|
74 |
- uint8_t solid; |
|
75 |
- uint8_t freecomp; |
|
76 |
- uint8_t eof; |
|
77 | 73 |
char ofn[1024]; |
78 | 74 |
}; |
79 | 75 |
|
... | ... |
@@ -92,7 +99,7 @@ static int nsis_init(struct nsis_st *n) { |
92 | 92 |
break; |
93 | 93 |
case COMP_LZMA: |
94 | 94 |
memset(&n->lz, 0, sizeof(CLI_LZMA)); |
95 |
- cli_LzmaInit(&n->lz, 0xffffffffffffffff); |
|
95 |
+ cli_LzmaInit(&n->lz, 0xffffffffffffffffULL); |
|
96 | 96 |
n->freecomp=1; |
97 | 97 |
break; |
98 | 98 |
case COMP_ZLIB: |
... | ... |
@@ -321,8 +328,21 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) { |
321 | 321 |
close(n->ofd); |
322 | 322 |
return ret; |
323 | 323 |
} |
324 |
+#if HAVE_MMAP |
|
325 |
+ if((n->freeme= (unsigned char *)mmap(NULL, n->fullsz, PROT_READ, MAP_PRIVATE, n->ifd, 0))==MAP_FAILED) { |
|
326 |
+ cli_dbgmsg("NSIS: mmap() failed"__AT__"\n"); |
|
327 |
+ close(n->ofd); |
|
328 |
+ return CL_EIO; |
|
329 |
+ } |
|
330 |
+ n->nsis.next_in = n->freeme+n->off+0x1c; |
|
331 |
+#else /* HAVE_MMAP */ |
|
332 |
+ if(!size || size > CLI_MAX_ALLOCATION) { |
|
333 |
+ cli_dbgmsg("NSIS: mmap() support not compiled in and input file too big\n"); |
|
334 |
+ close(n->ofd); |
|
335 |
+ return CL_EMEM; |
|
336 |
+ } |
|
324 | 337 |
if (!(n->freeme= (unsigned char *) cli_malloc(n->asz))) { |
325 |
- cli_dbgmsg("NSIS: out of memory\n"); |
|
338 |
+ cli_dbgmsg("NSIS: out of memory"__AT__"\n"); |
|
326 | 339 |
close(n->ofd); |
327 | 340 |
return CL_EMEM; |
328 | 341 |
} |
... | ... |
@@ -332,6 +352,7 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) { |
332 | 332 |
return CL_EIO; |
333 | 333 |
} |
334 | 334 |
n->nsis.next_in = n->freeme; |
335 |
+#endif /* HAVE_MMAP */ |
|
335 | 336 |
n->nsis.avail_in = n->asz; |
336 | 337 |
} |
337 | 338 |
|
... | ... |
@@ -424,6 +445,7 @@ static int nsis_headers(struct nsis_st *n, cli_ctx *ctx) { |
424 | 424 |
|
425 | 425 |
n->hsz = (uint32_t)cli_readint32(buf+0x14); |
426 | 426 |
n->asz = (uint32_t)cli_readint32(buf+0x18); |
427 |
+ n->fullsz = st.st_size; |
|
427 | 428 |
|
428 | 429 |
cli_dbgmsg("NSIS: Header info - Flags=%x, Header size=%x, Archive size=%x\n", cli_readint32(buf), n->hsz, n->asz); |
429 | 430 |
|
... | ... |
@@ -481,7 +503,13 @@ static int cli_nsis_unpack(struct nsis_st *n, cli_ctx *ctx) { |
481 | 481 |
|
482 | 482 |
static void cli_nsis_free(struct nsis_st *n) { |
483 | 483 |
nsis_shutdown(n); |
484 |
- if (n->solid && n->freeme) free(n->freeme); |
|
484 |
+ if (n->solid && n->freeme) { |
|
485 |
+#if HAVE_MMAP |
|
486 |
+ munmap(n->freeme, n->fullsz); |
|
487 |
+#else |
|
488 |
+ free(n->freeme); |
|
489 |
+#endif |
|
490 |
+ } |
|
485 | 491 |
} |
486 | 492 |
|
487 | 493 |
int cli_scannulsft(int desc, cli_ctx *ctx, off_t offset) { |