Browse code

* libclamav/matcher-ac.c (cli_ac_addsig): need to use mpool allocated memory for ->str * libclamav/mpool.c (mp_malloc, cli_mp_hex2str, check_all): introduce hex2str wrapper * libclamav/mpool.h (mp_t, cli_mp_hex2str): introduce hex2str wrapper * libclamav/regex_list.c (add_hash): need to use mpool allocated memory for arg to bm_addpatt

git-svn: trunk@4330

Török Edvin authored on 2008/11/04 19:40:31
Showing 5 changed files
... ...
@@ -1,3 +1,10 @@
1
+Tue Nov  4 12:56:46 EET 2008 (edwin)
2
+------------------------------------
3
+ * libclamav/matcher-ac.c (cli_ac_addsig): need to use mpool allocated memory for ->str
4
+ * libclamav/mpool.c (mp_malloc, cli_mp_hex2str, check_all): introduce hex2str wrapper
5
+ * libclamav/mpool.h (mp_t, cli_mp_hex2str): introduce hex2str wrapper
6
+ * libclamav/regex_list.c (add_hash): need to use mpool allocated memory for arg to bm_addpatt
7
+
1 8
 Tue Nov  4 12:36:29 EET 2008 (edwin)
2 9
 ------------------------------------
3 10
  * libclamav/mpool.c, unit_tests/check_clamav.c,
... ...
@@ -1287,7 +1287,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1287 1287
 		    break;
1288 1288
 		}
1289 1289
 
1290
-		if(!(c = cli_hex2str(h))) {
1290
+		if(!(c = cli_mp_hex2str(root->mempool, h))) {
1291 1291
 		    free(h);
1292 1292
 		    error = CL_EMALFDB;
1293 1293
 		    break;
... ...
@@ -1295,7 +1295,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1295 1295
 
1296 1296
 		if(newalt->chmode) {
1297 1297
 		    newalt->str[i] = *c;
1298
-		    free(c);
1298
+		    mp_free(root->mempool, c);
1299 1299
 		} else {
1300 1300
 		    if(i) {
1301 1301
 			altpt = newalt;
... ...
@@ -39,6 +39,7 @@
39 39
 #include <stddef.h>
40 40
 
41 41
 #include "others.h"
42
+#include "str.h"
42 43
 #ifndef CL_DEBUG
43 44
 #define NDEBUG
44 45
 #endif
... ...
@@ -400,6 +401,9 @@ void *mp_malloc(struct MP *mp, size_t size) {
400 400
   if((f = mp->avail[sbits])) {
401 401
     spam("malloc %p size %u (freed)\n", f, roundup(size));
402 402
     mp->avail[sbits] = f->next;
403
+#ifdef CL_DEBUG
404
+      f->magic = MPOOLMAGIC;
405
+#endif
403 406
     return &f->fake;
404 407
   }
405 408
 
... ...
@@ -510,6 +514,20 @@ void *mp_realloc2(struct MP *mp, void *ptr, size_t size) {
510 510
   return new_ptr;
511 511
 }
512 512
 
513
+unsigned char *cli_mp_hex2str(mp_t *mp, const unsigned char *str)
514
+{
515
+	unsigned char *tmp = cli_hex2str(str);
516
+	if(tmp) {
517
+		unsigned char *res;
518
+		unsigned int tmpsz = strlen(str) / 2 + 1;
519
+		if((res = mp_malloc(mp, tmpsz)))
520
+			memcpy(res, tmp, tmpsz);
521
+		free(tmp);
522
+		return res;
523
+	}
524
+	return NULL;
525
+}
526
+
513 527
 #ifdef DEBUGMPOOL
514 528
 void mp_stats(struct MP *mp) {
515 529
   unsigned int i=0, ta=0, tu=0;
... ...
@@ -540,4 +558,6 @@ void check_all(struct MP *mp) {
540 540
 }
541 541
 #endif /* DEBUGMPOOL */
542 542
 
543
+
544
+
543 545
 #endif /* USE_MPOOL */
... ...
@@ -32,7 +32,7 @@ void mp_free(mp_t *mp, void *ptr);
32 32
 void *mp_calloc(mp_t *mp, size_t nmemb, size_t size);
33 33
 void *mp_realloc(mp_t *mp, void *ptr, size_t size);
34 34
 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
 #else /* USE_MPOOL */
37 37
 
38 38
 #define mp_malloc(a, b) cli_malloc(b)
... ...
@@ -40,6 +40,7 @@ void *mp_realloc2(mp_t *mp, void *ptr, size_t size);
40 40
 #define mp_calloc(a, b, c) cli_calloc(b, c)
41 41
 #define mp_realloc(a, b, c) cli_realloc(b, c)
42 42
 #define mp_realloc2(a, b, c) cli_realloc2(b, c)
43
+#define cli_mp_hex2str(mp, src) cli_hex2str(src)
43 44
 
44 45
 #endif /* USE_MPOOL */
45 46
 
... ...
@@ -422,14 +422,14 @@ static int functionality_level_check(char* line)
422 422
 static int add_hash(struct regex_matcher *matcher, char* pattern, const char fl)
423 423
 {
424 424
 	int rc;
425
-	struct cli_bm_patt *pat = cli_calloc(1, sizeof(*pat));
425
+	struct cli_bm_patt *pat = mp_calloc(matcher->mempool, 1, sizeof(*pat));
426 426
 	if(!pat)
427 427
 		return CL_EMEM;
428
-	pat->pattern = (unsigned char*)cli_hex2str(pattern);
428
+	pat->pattern = (unsigned char*)cli_mp_hex2str(matcher->mempool, pattern);
429 429
 	if(!pat->pattern)
430 430
 		return CL_EMALFDB;
431 431
 	pat->length = 16;
432
-	pat->virname = cli_malloc(1);
432
+	pat->virname = mp_malloc(matcher->mempool, 1);
433 433
 	if(!pat->virname) {
434 434
 		free(pat);
435 435
 		return CL_EMEM;