mpool cli_mp_hex2ui

git-svn: trunk@4337
0.95
aCaB 17 years ago
parent e9f6bb39e5
commit 38e881e3c0
  1. 5
      ChangeLog
  2. 15
      libclamav/matcher-ac.c
  3. 23
      libclamav/mpool.c
  4. 2
      libclamav/mpool.h
  5. 58
      libclamav/str.c
  6. 1
      libclamav/str.h

@ -1,3 +1,8 @@
Tue Nov 4 23:15:43 CET 2008 (acab)
-----------------------------------
* libclamav: mempool de-uglify last ugly bit
please build with ./configure --enable-mempool and report memory usage
Tue Nov 4 23:02:27 EET 2008 (edwin)
------------------------------------
* 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
}
}
#ifdef USE_MPOOL
{
unsigned int mpoolpattsz = (strlen(hex ? hex : hexsig) / 2 + 1) * sizeof(uint16_t);
uint16_t *mpoolpatt = cli_hex2ui(hex ? hex : hexsig);
if(mpoolpatt) {
if((new->pattern = mp_malloc(root->mempool, mpoolpattsz)) != NULL)
memcpy(new->pattern, mpoolpatt, mpoolpattsz);
free(mpoolpatt);
} else new->pattern = NULL;
}
#else
new->pattern = cli_hex2ui(hex ? hex : hexsig);
#endif
new->pattern = cli_mp_hex2ui(root->mempool, hex ? hex : hexsig);
if(new->pattern == NULL) {
if(new->alt)
mp_ac_free_alt(root->mempool, new);

@ -573,6 +573,29 @@ char *cli_mp_virname(mp_t *mp, char *virname, unsigned int official) {
}
uint16_t *cli_mp_hex2ui(mp_t *mp, const char *hex) {
uint16_t *str;
unsigned int len;
len = strlen(hex);
if(len % 2 != 0) {
cli_errmsg("cli_hex2si(): Malformed hexstring: %s (length: %u)\n", hex, len);
return NULL;
}
str = mp_calloc(mp, (len / 2) + 1, sizeof(uint16_t));
if(!str)
return NULL;
if(cli_realhex2ui(hex, str, len))
return str;
free(str);
return NULL;
}
#ifdef DEBUGMPOOL
void mp_stats(struct MP *mp) {
unsigned int i=0, ta=0, tu=0;

@ -35,6 +35,7 @@ void *mp_realloc2(mp_t *mp, void *ptr, size_t size);
unsigned char *cli_mp_hex2str(mp_t* mp, const unsigned char *src);
char *cli_mp_strdup(mp_t *mp, const char *s);
char *cli_mp_virname(mp_t *mp, char *virname, unsigned int official);
uint16_t *cli_mp_hex2ui(mp_t *mp, const char *hex);
#else /* USE_MPOOL */
#define mp_malloc(a, b) cli_malloc(b)
@ -45,6 +46,7 @@ char *cli_mp_virname(mp_t *mp, char *virname, unsigned int official);
#define cli_mp_hex2str(mp, src) cli_hex2str(src)
#define cli_mp_strdup(mp, s) cli_strdup(s)
#define cli_mp_virname(mp, a, b) cli_virname(a, b)
#define cli_mp_hex2ui(mp, hex) cli_hex2ui(hex)
#endif /* USE_MPOOL */
#endif

@ -63,25 +63,11 @@ static inline int cli_hex2int(const char c)
return hex_chars[(const unsigned char)c];
}
uint16_t *cli_hex2ui(const char *hex)
{
uint16_t *str, *ptr, val;
unsigned int i, len;
int c;
len = strlen(hex);
if(len % 2 != 0) {
cli_errmsg("cli_hex2si(): Malformed hexstring: %s (length: %u)\n", hex, len);
return NULL;
}
str = cli_calloc((len / 2) + 1, sizeof(uint16_t));
if(!str)
return NULL;
ptr = str;
int cli_realhex2ui(const char *hex, uint16_t *ptr, unsigned int len) {
uint16_t val;
unsigned int i;
int c;
for(i = 0; i < len; i += 2) {
val = 0;
@ -93,8 +79,7 @@ uint16_t *cli_hex2ui(const char *hex)
if((c = cli_hex2int(hex[i])) >= 0) {
val = c << 4;
} else {
free(str);
return NULL;
return 0;
}
val |= CLI_MATCH_NIBBLE_HIGH;
@ -102,8 +87,7 @@ uint16_t *cli_hex2ui(const char *hex)
if((c = cli_hex2int(hex[i + 1])) >= 0) {
val = c;
} else {
free(str);
return NULL;
return 0;
}
val |= CLI_MATCH_NIBBLE_LOW;
@ -116,19 +100,39 @@ uint16_t *cli_hex2ui(const char *hex)
if((c = cli_hex2int(hex[i+1])) >= 0) {
val = (val << 4) + c;
} else {
free(str);
return NULL;
return 0;
}
} else {
free(str);
return NULL;
return 0;
}
}
*ptr++ = val;
}
return 1;
}
return str;
uint16_t *cli_hex2ui(const char *hex)
{
uint16_t *str;
unsigned int len;
len = strlen(hex);
if(len % 2 != 0) {
cli_errmsg("cli_hex2si(): Malformed hexstring: %s (length: %u)\n", hex, len);
return NULL;
}
str = cli_calloc((len / 2) + 1, sizeof(uint16_t));
if(!str)
return NULL;
if(cli_realhex2ui(hex, str, len))
return str;
free(str);
return NULL;
}
char *cli_hex2str(const char *hex)

@ -34,6 +34,7 @@ const char *cli_strcasestr(const char *haystack, const char *needle);
int cli_strbcasestr(const char *haystack, const char *needle);
int cli_chomp(char *string);
char *cli_strtok(const char *line, int field, const char *delim);
int cli_realhex2ui(const char *hex, uint16_t *ptr, unsigned int len);
uint16_t *cli_hex2ui(const char *hex);
char *cli_hex2str(const char *hex);
int cli_hex2num(const char *hex);

Loading…
Cancel
Save