| ... | ... |
@@ -1,3 +1,8 @@ |
| 1 |
+Tue Nov 4 23:15:43 CET 2008 (acab) |
|
| 2 |
+----------------------------------- |
|
| 3 |
+ * libclamav: mempool de-uglify last ugly bit |
|
| 4 |
+ please build with ./configure --enable-mempool and report memory usage |
|
| 5 |
+ |
|
| 1 | 6 |
Tue Nov 4 23:02:27 EET 2008 (edwin) |
| 2 | 7 |
------------------------------------ |
| 3 | 8 |
* contrib/clamdtop/TODO: add more TODO notes, thanks nitrox for the |
| ... | ... |
@@ -1372,20 +1372,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex |
| 1372 | 1372 |
} |
| 1373 | 1373 |
} |
| 1374 | 1374 |
|
| 1375 |
-#ifdef USE_MPOOL |
|
| 1376 |
-{
|
|
| 1377 |
- unsigned int mpoolpattsz = (strlen(hex ? hex : hexsig) / 2 + 1) * sizeof(uint16_t); |
|
| 1378 |
- uint16_t *mpoolpatt = cli_hex2ui(hex ? hex : hexsig); |
|
| 1379 |
- if(mpoolpatt) {
|
|
| 1380 |
- if((new->pattern = mp_malloc(root->mempool, mpoolpattsz)) != NULL) |
|
| 1381 |
- memcpy(new->pattern, mpoolpatt, mpoolpattsz); |
|
| 1382 |
- free(mpoolpatt); |
|
| 1383 |
- } else new->pattern = NULL; |
|
| 1384 |
-} |
|
| 1385 |
-#else |
|
| 1386 |
- new->pattern = cli_hex2ui(hex ? hex : hexsig); |
|
| 1387 |
-#endif |
|
| 1388 |
- |
|
| 1375 |
+ new->pattern = cli_mp_hex2ui(root->mempool, hex ? hex : hexsig); |
|
| 1389 | 1376 |
if(new->pattern == NULL) {
|
| 1390 | 1377 |
if(new->alt) |
| 1391 | 1378 |
mp_ac_free_alt(root->mempool, new); |
| ... | ... |
@@ -573,6 +573,29 @@ char *cli_mp_virname(mp_t *mp, char *virname, unsigned int official) {
|
| 573 | 573 |
} |
| 574 | 574 |
|
| 575 | 575 |
|
| 576 |
+uint16_t *cli_mp_hex2ui(mp_t *mp, const char *hex) {
|
|
| 577 |
+ uint16_t *str; |
|
| 578 |
+ unsigned int len; |
|
| 579 |
+ |
|
| 580 |
+ len = strlen(hex); |
|
| 581 |
+ |
|
| 582 |
+ if(len % 2 != 0) {
|
|
| 583 |
+ cli_errmsg("cli_hex2si(): Malformed hexstring: %s (length: %u)\n", hex, len);
|
|
| 584 |
+ return NULL; |
|
| 585 |
+ } |
|
| 586 |
+ |
|
| 587 |
+ str = mp_calloc(mp, (len / 2) + 1, sizeof(uint16_t)); |
|
| 588 |
+ if(!str) |
|
| 589 |
+ return NULL; |
|
| 590 |
+ |
|
| 591 |
+ if(cli_realhex2ui(hex, str, len)) |
|
| 592 |
+ return str; |
|
| 593 |
+ |
|
| 594 |
+ free(str); |
|
| 595 |
+ return NULL; |
|
| 596 |
+} |
|
| 597 |
+ |
|
| 598 |
+ |
|
| 576 | 599 |
#ifdef DEBUGMPOOL |
| 577 | 600 |
void mp_stats(struct MP *mp) {
|
| 578 | 601 |
unsigned int i=0, ta=0, tu=0; |
| ... | ... |
@@ -35,6 +35,7 @@ void *mp_realloc2(mp_t *mp, void *ptr, size_t size); |
| 35 | 35 |
unsigned char *cli_mp_hex2str(mp_t* mp, const unsigned char *src); |
| 36 | 36 |
char *cli_mp_strdup(mp_t *mp, const char *s); |
| 37 | 37 |
char *cli_mp_virname(mp_t *mp, char *virname, unsigned int official); |
| 38 |
+uint16_t *cli_mp_hex2ui(mp_t *mp, const char *hex); |
|
| 38 | 39 |
#else /* USE_MPOOL */ |
| 39 | 40 |
|
| 40 | 41 |
#define mp_malloc(a, b) cli_malloc(b) |
| ... | ... |
@@ -45,6 +46,7 @@ char *cli_mp_virname(mp_t *mp, char *virname, unsigned int official); |
| 45 | 45 |
#define cli_mp_hex2str(mp, src) cli_hex2str(src) |
| 46 | 46 |
#define cli_mp_strdup(mp, s) cli_strdup(s) |
| 47 | 47 |
#define cli_mp_virname(mp, a, b) cli_virname(a, b) |
| 48 |
+#define cli_mp_hex2ui(mp, hex) cli_hex2ui(hex) |
|
| 48 | 49 |
#endif /* USE_MPOOL */ |
| 49 | 50 |
|
| 50 | 51 |
#endif |
| ... | ... |
@@ -63,25 +63,11 @@ static inline int cli_hex2int(const char c) |
| 63 | 63 |
return hex_chars[(const unsigned char)c]; |
| 64 | 64 |
} |
| 65 | 65 |
|
| 66 |
-uint16_t *cli_hex2ui(const char *hex) |
|
| 67 |
-{
|
|
| 68 |
- uint16_t *str, *ptr, val; |
|
| 69 |
- unsigned int i, len; |
|
| 70 |
- int c; |
|
| 71 |
- |
|
| 72 |
- |
|
| 73 |
- len = strlen(hex); |
|
| 74 |
- |
|
| 75 |
- if(len % 2 != 0) {
|
|
| 76 |
- cli_errmsg("cli_hex2si(): Malformed hexstring: %s (length: %u)\n", hex, len);
|
|
| 77 |
- return NULL; |
|
| 78 |
- } |
|
| 79 | 66 |
|
| 80 |
- str = cli_calloc((len / 2) + 1, sizeof(uint16_t)); |
|
| 81 |
- if(!str) |
|
| 82 |
- return NULL; |
|
| 83 |
- |
|
| 84 |
- ptr = str; |
|
| 67 |
+int cli_realhex2ui(const char *hex, uint16_t *ptr, unsigned int len) {
|
|
| 68 |
+ uint16_t val; |
|
| 69 |
+ unsigned int i; |
|
| 70 |
+ int c; |
|
| 85 | 71 |
|
| 86 | 72 |
for(i = 0; i < len; i += 2) {
|
| 87 | 73 |
val = 0; |
| ... | ... |
@@ -93,8 +79,7 @@ uint16_t *cli_hex2ui(const char *hex) |
| 93 | 93 |
if((c = cli_hex2int(hex[i])) >= 0) {
|
| 94 | 94 |
val = c << 4; |
| 95 | 95 |
} else {
|
| 96 |
- free(str); |
|
| 97 |
- return NULL; |
|
| 96 |
+ return 0; |
|
| 98 | 97 |
} |
| 99 | 98 |
val |= CLI_MATCH_NIBBLE_HIGH; |
| 100 | 99 |
|
| ... | ... |
@@ -102,8 +87,7 @@ uint16_t *cli_hex2ui(const char *hex) |
| 102 | 102 |
if((c = cli_hex2int(hex[i + 1])) >= 0) {
|
| 103 | 103 |
val = c; |
| 104 | 104 |
} else {
|
| 105 |
- free(str); |
|
| 106 |
- return NULL; |
|
| 105 |
+ return 0; |
|
| 107 | 106 |
} |
| 108 | 107 |
val |= CLI_MATCH_NIBBLE_LOW; |
| 109 | 108 |
|
| ... | ... |
@@ -116,19 +100,39 @@ uint16_t *cli_hex2ui(const char *hex) |
| 116 | 116 |
if((c = cli_hex2int(hex[i+1])) >= 0) {
|
| 117 | 117 |
val = (val << 4) + c; |
| 118 | 118 |
} else {
|
| 119 |
- free(str); |
|
| 120 |
- return NULL; |
|
| 119 |
+ return 0; |
|
| 121 | 120 |
} |
| 122 | 121 |
} else {
|
| 123 |
- free(str); |
|
| 124 |
- return NULL; |
|
| 122 |
+ return 0; |
|
| 125 | 123 |
} |
| 126 | 124 |
} |
| 127 | 125 |
|
| 128 | 126 |
*ptr++ = val; |
| 129 | 127 |
} |
| 128 |
+ return 1; |
|
| 129 |
+} |
|
| 130 | 130 |
|
| 131 |
- return str; |
|
| 131 |
+uint16_t *cli_hex2ui(const char *hex) |
|
| 132 |
+{
|
|
| 133 |
+ uint16_t *str; |
|
| 134 |
+ unsigned int len; |
|
| 135 |
+ |
|
| 136 |
+ len = strlen(hex); |
|
| 137 |
+ |
|
| 138 |
+ if(len % 2 != 0) {
|
|
| 139 |
+ cli_errmsg("cli_hex2si(): Malformed hexstring: %s (length: %u)\n", hex, len);
|
|
| 140 |
+ return NULL; |
|
| 141 |
+ } |
|
| 142 |
+ |
|
| 143 |
+ str = cli_calloc((len / 2) + 1, sizeof(uint16_t)); |
|
| 144 |
+ if(!str) |
|
| 145 |
+ return NULL; |
|
| 146 |
+ |
|
| 147 |
+ if(cli_realhex2ui(hex, str, len)) |
|
| 148 |
+ return str; |
|
| 149 |
+ |
|
| 150 |
+ free(str); |
|
| 151 |
+ return NULL; |
|
| 132 | 152 |
} |
| 133 | 153 |
|
| 134 | 154 |
char *cli_hex2str(const char *hex) |
| ... | ... |
@@ -34,6 +34,7 @@ const char *cli_strcasestr(const char *haystack, const char *needle); |
| 34 | 34 |
int cli_strbcasestr(const char *haystack, const char *needle); |
| 35 | 35 |
int cli_chomp(char *string); |
| 36 | 36 |
char *cli_strtok(const char *line, int field, const char *delim); |
| 37 |
+int cli_realhex2ui(const char *hex, uint16_t *ptr, unsigned int len); |
|
| 37 | 38 |
uint16_t *cli_hex2ui(const char *hex); |
| 38 | 39 |
char *cli_hex2str(const char *hex); |
| 39 | 40 |
int cli_hex2num(const char *hex); |