* 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
0.95
Török Edvin 17 years ago
parent 7866b37c6b
commit ad0fd7287a
  1. 7
      ChangeLog
  2. 4
      libclamav/matcher-ac.c
  3. 20
      libclamav/mpool.c
  4. 3
      libclamav/mpool.h
  5. 6
      libclamav/regex_list.c

@ -1,3 +1,10 @@
Tue Nov 4 12:56:46 EET 2008 (edwin)
------------------------------------
* 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
Tue Nov 4 12:36:29 EET 2008 (edwin)
------------------------------------
* 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
break;
}
if(!(c = cli_hex2str(h))) {
if(!(c = cli_mp_hex2str(root->mempool, h))) {
free(h);
error = CL_EMALFDB;
break;
@ -1295,7 +1295,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
if(newalt->chmode) {
newalt->str[i] = *c;
free(c);
mp_free(root->mempool, c);
} else {
if(i) {
altpt = newalt;

@ -39,6 +39,7 @@
#include <stddef.h>
#include "others.h"
#include "str.h"
#ifndef CL_DEBUG
#define NDEBUG
#endif
@ -400,6 +401,9 @@ void *mp_malloc(struct MP *mp, size_t size) {
if((f = mp->avail[sbits])) {
spam("malloc %p size %u (freed)\n", f, roundup(size));
mp->avail[sbits] = f->next;
#ifdef CL_DEBUG
f->magic = MPOOLMAGIC;
#endif
return &f->fake;
}
@ -510,6 +514,20 @@ void *mp_realloc2(struct MP *mp, void *ptr, size_t size) {
return new_ptr;
}
unsigned char *cli_mp_hex2str(mp_t *mp, const unsigned char *str)
{
unsigned char *tmp = cli_hex2str(str);
if(tmp) {
unsigned char *res;
unsigned int tmpsz = strlen(str) / 2 + 1;
if((res = mp_malloc(mp, tmpsz)))
memcpy(res, tmp, tmpsz);
free(tmp);
return res;
}
return NULL;
}
#ifdef DEBUGMPOOL
void mp_stats(struct MP *mp) {
unsigned int i=0, ta=0, tu=0;
@ -540,4 +558,6 @@ void check_all(struct MP *mp) {
}
#endif /* DEBUGMPOOL */
#endif /* USE_MPOOL */

@ -32,7 +32,7 @@ void mp_free(mp_t *mp, void *ptr);
void *mp_calloc(mp_t *mp, size_t nmemb, size_t size);
void *mp_realloc(mp_t *mp, void *ptr, size_t size);
void *mp_realloc2(mp_t *mp, void *ptr, size_t size);
unsigned char *cli_mp_hex2str(mp_t* mp, const unsigned char *src);
#else /* USE_MPOOL */
#define mp_malloc(a, b) cli_malloc(b)
@ -40,6 +40,7 @@ void *mp_realloc2(mp_t *mp, void *ptr, size_t size);
#define mp_calloc(a, b, c) cli_calloc(b, c)
#define mp_realloc(a, b, c) cli_realloc(b, c)
#define mp_realloc2(a, b, c) cli_realloc2(b, c)
#define cli_mp_hex2str(mp, src) cli_hex2str(src)
#endif /* USE_MPOOL */

@ -422,14 +422,14 @@ static int functionality_level_check(char* line)
static int add_hash(struct regex_matcher *matcher, char* pattern, const char fl)
{
int rc;
struct cli_bm_patt *pat = cli_calloc(1, sizeof(*pat));
struct cli_bm_patt *pat = mp_calloc(matcher->mempool, 1, sizeof(*pat));
if(!pat)
return CL_EMEM;
pat->pattern = (unsigned char*)cli_hex2str(pattern);
pat->pattern = (unsigned char*)cli_mp_hex2str(matcher->mempool, pattern);
if(!pat->pattern)
return CL_EMALFDB;
pat->length = 16;
pat->virname = cli_malloc(1);
pat->virname = mp_malloc(matcher->mempool, 1);
if(!pat->virname) {
free(pat);
return CL_EMEM;

Loading…
Cancel
Save