bb6258 - Add warnings when allocations fail

pull/1/head
Shawn Webb 13 years ago
parent 63c6b0e21b
commit 241e7eb147
  1. 12
      libclamav/bytecode.c
  2. 6
      libclamav/bytecode_vm.c
  3. 15
      libclamav/hashtab.c
  4. 8
      libclamav/htmlnorm.c
  5. 6
      libclamav/ishield.c
  6. 6
      libclamav/line.c
  7. 10
      libclamav/matcher-ac.c
  8. 10
      libclamav/mbox.c
  9. 12
      libclamav/message.c
  10. 4
      libclamav/mspack.c
  11. 7
      libclamav/ole2_extract.c
  12. 10
      libclamav/others.c
  13. 16
      libclamav/pdf.c
  14. 9
      libclamav/pe.c
  15. 7
      libclamav/pe_icons.c
  16. 4
      libclamav/phish_domaincheck_db.c
  17. 4
      libclamav/phish_whitelist.c
  18. 12
      libclamav/phishcheck.c
  19. 38
      libclamav/readdb.c
  20. 18
      libclamav/regex_list.c
  21. 17
      libclamav/regex_suffix.c
  22. 9
      libclamav/rtf.c
  23. 2
      libclamav/scanners.c
  24. 1
      libclamav/sis.c
  25. 9
      libclamav/spin.c
  26. 10
      libclamav/str.c
  27. 4
      libclamav/table.c
  28. 9
      libclamav/text.c
  29. 8
      libclamav/tnef.c
  30. 16
      libclamav/unarj.c
  31. 5
      libclamav/unsp.c
  32. 19
      libclamav/vba_extract.c
  33. 5
      libclamav/wwunpack.c

@ -1390,8 +1390,10 @@ static int parseBB(struct cli_bc *bc, unsigned func, unsigned bb, unsigned char
return CL_EMALFDB;
}
bcfunc->dbgnodes = cli_malloc(num*sizeof(*bcfunc->dbgnodes));
if (!bcfunc->dbgnodes)
if (!bcfunc->dbgnodes) {
cli_errmsg("Unable to allocate memory for dbg nodes: %s\n", num*sizeof(*bcfunc->dbgnodes));
return CL_EMEM;
}
for (i=0;i<num;i++) {
bcfunc->dbgnodes[i] = readNumber(buffer, &offset, len, &ok);
if (!ok)
@ -2042,8 +2044,10 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
int ret=CL_SUCCESS;
bc->numGlobalBytes = 0;
gmap = cli_malloc(bc->num_globals*sizeof(*gmap));
if (!gmap)
return CL_EMEM;
if (!gmap) {
cli_errmsg("interpreter: Unable to allocate memory for global map: %u\n", bc->num_globals*sizeof(*gmap));
return CL_EMEM;
}
for (j=0;j<bc->num_globals;j++) {
uint16_t ty = bc->globaltys[j];
unsigned align = typealign(bc, ty);
@ -2055,6 +2059,7 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
if (bc->numGlobalBytes) {
bc->globalBytes = cli_calloc(1, bc->numGlobalBytes);
if (!bc->globalBytes) {
cli_errmsg("interpreter: Unable to allocate memory for globalBytes: %u\n", bc->numGlobalBytes);
free(gmap);
return CL_EMEM;
}
@ -2122,6 +2127,7 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
unsigned totValues = bcfunc->numValues + bcfunc->numConstants + bc->num_globals;
unsigned *map = cli_malloc(sizeof(*map)*totValues);
if (!map) {
cli_errmsg("interpreter: Unable to allocate memory for map: %u\n", sizeof(*map)*totValues);
free(gmap);
return CL_EMEM;
}

@ -150,8 +150,10 @@ static always_inline void* cli_stack_alloc(struct stack *stack, unsigned bytes)
}
/* not enough room here, allocate new chunk */
chunk = cli_malloc(sizeof(*stack->chunk));
if (!chunk)
return NULL;
if (!chunk) {
cli_warnmsg("cli_stack_alloc: Unable to allocate memory for stack-chunk: bytes: %u!\n", sizeof(*stack->chunk));
return NULL;
}
*(uint16_t*)&chunk->u.data[last_size_off] = stack->last_size;
stack->last_size = bytes/sizeof(align_t);

@ -451,8 +451,10 @@ const struct cli_element* cli_hashtab_insert(struct cli_hashtable *s, const char
PROFILE_INSERT(s, tries);
}
thekey = cli_malloc(len+1);
if(!thekey)
if(!thekey) {
cli_errmsg("hashtab.c: Unable to allocate memory for thekey\n");
return NULL;
}
strncpy(thekey, key, len+1);
thekey[len]='\0';
element->key = thekey;
@ -662,11 +664,13 @@ int cli_hashset_init(struct cli_hashset* hs, size_t initial_capacity, uint8_t lo
hs->keys = cli_malloc(initial_capacity * sizeof(*hs->keys));
hs->mempool = NULL;
if(!hs->keys) {
cli_errmsg("hashtab.c: Uable to allocate memory for hs->keys\n");
return CL_EMEM;
}
hs->bitmap = cli_calloc(initial_capacity >> 5, sizeof(*hs->bitmap));
if(!hs->bitmap) {
free(hs->keys);
cli_errmsg("hashtab.c: Unable to allocate memory for hs->bitmap\n");
return CL_EMEM;
}
return 0;
@ -685,11 +689,13 @@ int cli_hashset_init_pool(struct cli_hashset* hs, size_t initial_capacity, uint8
hs->mempool = mempool;
hs->keys = mpool_malloc(mempool, initial_capacity * sizeof(*hs->keys));
if(!hs->keys) {
cli_errmsg("hashtab.c: Unable to allocate memory pool for hs->keys\n");
return CL_EMEM;
}
hs->bitmap = mpool_calloc(mempool, initial_capacity >> 5, sizeof(*hs->bitmap));
if(!hs->bitmap) {
mpool_free(mempool, hs->keys);
cli_errmsg("hashtab.c: Unable to allocate/initialize memory for hs->keys\n");
return CL_EMEM;
}
return 0;
@ -820,6 +826,7 @@ ssize_t cli_hashset_toarray(const struct cli_hashset* hs, uint32_t** array)
}
*array = arr = cli_malloc(hs->count * sizeof(*arr));
if(!arr) {
cli_errmsg("hashtab.c: Unable to allocate memory for array\n");
return CL_EMEM;
}
@ -927,8 +934,10 @@ int cli_map_setvalue(struct cli_map *m, const void* value, int32_t valuesize)
if (v->value)
free(v->value);
v->value = cli_malloc(valuesize);
if (!v->value)
return -CL_EMEM;
if (!v->value) {
cli_errmsg("hashtab.c: Unable to allocate memory for v->value\n");
return -CL_EMEM;
}
memcpy(v->value, value, valuesize);
v->valuesize = valuesize;
}

@ -174,6 +174,7 @@ static unsigned char *cli_readchunk(FILE *stream, m_area_t *m_area, unsigned int
chunk = (unsigned char *) cli_malloc(max_len);
if (!chunk) {
cli_errmsg("readchunk: Unable to allocate memory for chunk\n");
return NULL;
}
@ -520,8 +521,10 @@ static inline void html_tag_contents_done(tag_arguments_t *tags,int idx, struct
unsigned char *p;
cont->contents[cont->pos++] = '\0';
p = cli_malloc(cont->pos);
if(!p)
if(!p) {
cli_errmsg("html_tag_contents_done: Unable to allocate memory for p\n");
return;
}
memcpy(p, cont->contents, cont->pos);
tags->contents[idx-1] = p;
cont->pos = 0;
@ -702,6 +705,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
file_buff_o2 = (file_buff_t *) cli_malloc(sizeof(file_buff_t));
if (!file_buff_o2) {
cli_errmsg("cli_html_normalise: Unable to allocate memory for file_buff_o2\n");
file_buff_o2 = file_buff_text = NULL;
goto abort;
}
@ -721,6 +725,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
close(file_buff_o2->fd);
free(file_buff_o2);
file_buff_o2 = file_buff_text = NULL;
cli_errmsg("cli_html_normalise: Unable to allocate memory for file_buff_text\n");
goto abort;
}
@ -1596,6 +1601,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
if (dirname) {
file_tmp_o1 = (file_buff_t *) cli_malloc(sizeof(file_buff_t));
if (!file_tmp_o1) {
cli_errmsg("cli_html_normalise: Unable to allocate memory for file_tmp_o1\n");
goto abort;
}
snprintf(filename, 1024, "%s"PATHSEP"rfc2397", dirname);

@ -692,8 +692,10 @@ static int is_extract_cab(cli_ctx *ctx, uint64_t off, uint64_t size, uint64_t cs
int success = 0;
fmap_t *map = *ctx->fmap;
if(!(outbuf = cli_malloc(IS_CABBUFSZ)))
return CL_EMEM;
if(!(outbuf = cli_malloc(IS_CABBUFSZ))) {
cli_errmsg("is_extract_cab: Unable to allocate memory for outbuf\n");
return CL_EMEM;
}
if(!(tempfile = cli_gentemp(ctx->engine->tmpdir))) {
free(outbuf);

@ -72,8 +72,10 @@ lineCreate(const char *data)
const size_t size = strlen(data);
line_t *ret = (line_t *)cli_malloc(size + 2);
if(ret == NULL)
return (line_t *)NULL;
if(ret == NULL) {
cli_errmsg("lineCreate: Unable to allocate memory for ret\n");
return (line_t *)NULL;
}
ret[0] = (char)1;
/*strcpy(&ret[1], data);*/

@ -1353,8 +1353,10 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
if(res) {
newres = (struct cli_ac_result *) malloc(sizeof(struct cli_ac_result));
if(!newres)
if(!newres) {
cli_errmsg("cli_ac_scanbuff: Can't allocate memory for newres %u\n", sizeof(struct cli_ac_result));
return CL_EMEM;
}
newres->virname = pt->virname;
newres->customdata = pt->customdata;
newres->next = *res;
@ -1404,8 +1406,10 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
if(res) {
newres = (struct cli_ac_result *) malloc(sizeof(struct cli_ac_result));
if(!newres)
return CL_EMEM;
if(!newres) {
cli_errmsg("cli_ac_scanbuff: Can't allocate memory for newres %u\n", sizeof(struct cli_ac_result));
return CL_EMEM;
}
newres->virname = pt->virname;
newres->customdata = pt->customdata;
newres->offset = realoff;

@ -2437,6 +2437,7 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c
buf = cli_malloc(strlen(ptr) + 1);
if(buf == NULL) {
cli_errmsg("parseMimeHeader: Unable to allocate memory for buf %u\n", strlen(ptr) + 1);
if(copy)
free(copy);
return -1;
@ -2545,6 +2546,7 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c
case CONTENT_DISPOSITION:
buf = cli_malloc(strlen(ptr) + 1);
if(buf == NULL) {
cli_errmsg("parseMimeHeader: Unable to allocate memory for buf %u\n", strlen(ptr) + 1);
if(copy)
free(copy);
return -1;
@ -2621,8 +2623,10 @@ rfc822comments(const char *in, char *out)
if(out == NULL) {
out = cli_malloc(strlen(in) + 1);
if(out == NULL)
if(out == NULL) {
cli_errmsg("rfc822comments: Unable to allocate memory for out %u\n", strlen(in) + 1);
return NULL;
}
}
backslash = commentlevel = inquote = 0;
@ -2687,8 +2691,10 @@ rfc2047(const char *in)
cli_dbgmsg("rfc2047 '%s'\n", in);
out = cli_malloc(strlen(in) + 1);
if(out == NULL)
if(out == NULL) {
cli_errmsg("rfc2047: Unable to allocate memory for out %u\n", strlen(in) + 1);
return NULL;
}
pout = out;

@ -889,8 +889,10 @@ messageAddLine(message *m, line_t *line)
m->body_last = m->body_last->t_next;
}
if(m->body_last == NULL)
if(m->body_last == NULL) {
cli_errmsg("messageAddLine: out of memory for m->body_last\n");
return -1;
}
m->body_last->t_next = NULL;
@ -2293,8 +2295,10 @@ rfc2231(const char *in)
/* Don't handle continuations, decode what we can */
p = ret = cli_malloc(strlen(in) + 16);
if(ret == NULL)
if(ret == NULL) {
cli_errmsg("rfc2331: out of memory, unable to proceed\n");
return NULL;
}
do {
switch(*in) {
@ -2347,8 +2351,10 @@ rfc2231(const char *in)
ret = cli_malloc(strlen(in) + 1);
if(ret == NULL)
if(ret == NULL) {
cli_errmsg("rfc2331: out of memory for ret\n");
return NULL;
}
/*
* memcpy(out, in, (ptr - in));

@ -603,12 +603,14 @@ struct mszip_stream *mszip_init(int ofd,
/* allocate decompression state */
if (!(zip = cli_calloc(1, sizeof(struct mszip_stream)))) {
cli_errmsg("mszip_stream: Unable to allocate zip buffer\n");
return NULL;
}
/* allocate input buffer */
zip->inbuf = cli_malloc((size_t) input_buffer_size);
if (!zip->inbuf) {
cli_errmsg("mszip_stream: Unable to allocate input buffer\n");
free(zip);
return NULL;
}
@ -1783,12 +1785,14 @@ struct qtm_stream *qtm_init(int ofd,
/* allocate decompression window and input buffer */
qtm->window = cli_malloc((size_t) window_size);
if (!qtm->window) {
cli_errmsg("qtm_init: Unable to allocate decompression window\n");
free(qtm);
return NULL;
}
qtm->inbuf = cli_malloc((size_t) input_buffer_size);
if (!qtm->inbuf) {
cli_errmsg("qtm_init: Unable to allocate input buffer\n");
free(qtm->window);
free(qtm);
return NULL;

@ -138,6 +138,7 @@ static char *get_property_name2(char *name, int size)
newname = (char *) cli_malloc(size*7);
if (!newname) {
cli_errmsg("OLE2 [get_property_name2]: Unable to allocate memory for newname: %u\n", size*7);
return NULL;
}
j=0;
@ -179,7 +180,10 @@ static char *get_property_name(char *name, int size) {
if (csize<=0) return NULL;
newname = cname = (char *)cli_malloc(size);
if (!newname) return NULL;
if (!newname) {
cli_errmsg("OLE2 [get_property_name]: Unable to allocate memory for newname %u\n", size);
return NULL;
}
while(--csize) {
uint16_t lo, hi, u=cli_readint16(oname)-0x3800;
@ -582,6 +586,7 @@ static int handler_writefile(ole2_header_t *hdr, property_t *prop, const char *d
buff = (unsigned char *) cli_malloc(1 << hdr->log2_big_block_size);
if (!buff) {
cli_errmsg("OLE2 [handler_writefile]: Unable to allocate memory for buff: %u\n", 1 << hdr->log2_big_block_size);
close(ofd);
return CL_BREAK;
}

@ -604,8 +604,10 @@ struct cl_settings *cl_engine_settings_copy(const struct cl_engine *engine)
struct cl_settings *settings;
settings = (struct cl_settings *) malloc(sizeof(struct cl_settings));
if(!settings)
return NULL;
if(!settings) {
cli_errmsg("cl_engine_settings_copy: Unable to allocate memory for settings %u\n", sizeof(struct cl_settings));
return NULL;
}
settings->ac_only = engine->ac_only;
settings->ac_mindepth = engine->ac_mindepth;
@ -929,6 +931,7 @@ cli_rmdirs(const char *name)
path = cli_malloc(strlen(name) + strlen(dent->d_name) + 2);
if(path == NULL) {
cli_errmsg("cli_rmdirs: Unable to allocate memory for path %u\n", strlen(name) + strlen(dent->d_name) + 2);
closedir(dd);
return -1;
}
@ -987,6 +990,7 @@ int cli_rmdirs(const char *dirname)
if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
path = cli_malloc(strlen(dirname) + strlen(dent->d_name) + 2);
if(!path) {
cli_errmsg("cli_rmdirs: Unable to allocate memory for path %u\n", strlen(dirname) + strlen(dent->d_name) + 2);
closedir(dd);
return -1;
}
@ -1058,11 +1062,13 @@ bitset_t *cli_bitset_init(void)
bs = cli_malloc(sizeof(bitset_t));
if (!bs) {
cli_errmsg("cli_bitset_init: Unable to allocate memory for bs %u\n", sizeof(bitset_t));
return NULL;
}
bs->length = BITSET_DEFAULT_SIZE;
bs->bitset = cli_calloc(BITSET_DEFAULT_SIZE, 1);
if (!bs->bitset) {
cli_errmsg("cli_bitset_init: Unable to allocate memory for bs->bitset %u\n", BITSET_DEFAULT_SIZE);
free(bs);
return NULL;
}

@ -955,7 +955,7 @@ static int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj)
if (obj->flags & (1 << OBJ_FILTER_AH)) {
ascii_decoded = cli_malloc(length/2 + 1);
if (!ascii_decoded) {
cli_errmsg("Cannot allocate memory for asciidecode\n");
cli_errmsg("Cannot allocate memory for ascii_decoded\n");
rc = CL_EMEM;
break;
}
@ -965,7 +965,7 @@ static int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj)
} else if (obj->flags & (1 << OBJ_FILTER_A85)) {
ascii_decoded = cli_malloc(length*5);
if (!ascii_decoded) {
cli_errmsg("Cannot allocate memory for asciidecode\n");
cli_errmsg("Cannot allocate memory for ascii_decoded\n");
rc = CL_EMEM;
break;
}
@ -1535,8 +1535,10 @@ static char *pdf_readstring(const char *q0, int len, const char *key, unsigned *
q--;
len = q - start;
s0 = s = cli_malloc(len + 1);
if (!s)
return NULL;
if (!s) {
cli_errmsg("pdf_readstring: Unable to allocate buffer\n");
return NULL;
}
end = start + len;
if (noescape) {
memcpy(s0, start, len);
@ -1729,8 +1731,10 @@ static void check_user_password(struct pdf_struct *pdf, int R, const char *O,
} else {
pdf->keylen = 32;
pdf->key = cli_malloc(32);
if (!pdf->key)
return;
if (!pdf->key) {
cli_errmsg("check_user_password: Cannot allocate memory for pdf->key\n");
return;
}
aes_decrypt(UE, &n, pdf->key, result2, 32, 0);
dbg_printhex("cli_pdf: Candidate encryption key", pdf->key, pdf->keylen);
}

@ -1694,6 +1694,7 @@ int cli_scanpe(cli_ctx *ctx)
}
if((sections = (struct cli_exe_section *) cli_malloc((sectcnt + 1) * sizeof(struct cli_exe_section))) == NULL) {
cli_errmsg("FSG: Unable to allocate memory for sections %u\n", (sectcnt + 1) * sizeof(struct cli_exe_section));
free(exe_sections);
return CL_EMEM;
}
@ -1793,6 +1794,7 @@ int cli_scanpe(cli_ctx *ctx)
}
if((sections = (struct cli_exe_section *) cli_malloc((sectcnt + 1) * sizeof(struct cli_exe_section))) == NULL) {
cli_errmsg("FSG: Unable to allocate memory for sections %u\n", (sectcnt + 1) * sizeof(struct cli_exe_section));
free(exe_sections);
return CL_EMEM;
}
@ -2040,6 +2042,7 @@ int cli_scanpe(cli_ctx *ctx)
CLI_UNPSIZELIMITS("PEspin", fsize);
if((spinned = (char *) cli_malloc(fsize)) == NULL) {
cli_errmsg("PESping: Unable to allocate memory for spinned %u\n", fsize);
free(exe_sections);
return CL_EMEM;
}
@ -2103,6 +2106,7 @@ int cli_scanpe(cli_ctx *ctx)
char *spinned;
if((spinned = (char *) cli_malloc(fsize)) == NULL) {
cli_errmsg("yc: Unable to allocate memory for spinned %u\n", fsize);
free(exe_sections);
return CL_EMEM;
}
@ -2250,7 +2254,10 @@ int cli_scanpe(cli_ctx *ctx)
CLI_UNPSIZELIMITS("NsPack", MAX(ssize,dsize));
if (!ssize || !dsize || dsize != exe_sections[0].vsz) break;
if (!(dest=cli_malloc(dsize))) break;
if (!(dest=cli_malloc(dsize))) {
cli_errmsg("NsPack: Unable to allocate memory for dest %u\n", dsize);
break;
}
/* memset(dest, 0xfc, dsize); */
if(!(src = fmap_need_off(map, start_of_stuff, ssize))) {

@ -776,8 +776,10 @@ static int getmetrics(unsigned int side, unsigned int *imagedata, struct icomtr
unsigned int edge_avg[6], edge_x[6]={0,0,0,0,0,0}, edge_y[6]={0,0,0,0,0,0}, noedge_avg[6], noedge_x[6]={0,0,0,0,0,0}, noedge_y[6]={0,0,0,0,0,0};
double *sobel;
if(!(tmp = cli_malloc(side*side*4*2)))
return CL_EMEM;
if(!(tmp = cli_malloc(side*side*4*2))) {
cli_errmsg("getmetrics: Unable to allocate memory for tmp %u\n", (side*side*4*2));
return CL_EMEM;
}
memset(res, 0, sizeof(*res));
@ -939,6 +941,7 @@ static int getmetrics(unsigned int side, unsigned int *imagedata, struct icomtr
#ifdef USE_FLOATS
sobel = cli_malloc(side * side * sizeof(double));
if(!sobel) {
cli_errmsg("getmetrics: Unable to allocate memory for edge detection %u\n", (side * side * sizeof(double)));
free(tmp);
return CL_EMEM;
}

@ -51,8 +51,10 @@ int init_domainlist(struct cl_engine* engine)
{
if(engine) {
engine->domainlist_matcher = (struct regex_matcher *) cli_malloc(sizeof(struct regex_matcher));
if(!engine->domainlist_matcher)
if(!engine->domainlist_matcher) {
cli_errmsg("Phishcheck: Unable to allocate memory for init_domainlist\n");
return CL_EMEM;
}
#ifdef USE_MPOOL
((struct regex_matcher*)engine->domainlist_matcher)->mempool = engine->mempool;
#endif

@ -52,8 +52,10 @@ int init_whitelist(struct cl_engine* engine)
{
if(engine) {
engine->whitelist_matcher = (struct regex_matcher *) mpool_malloc(engine->mempool, sizeof(struct regex_matcher));
if(!engine->whitelist_matcher)
if(!engine->whitelist_matcher) {
cli_errmsg("Phish_whitelist: Unable to allocate memory for whitelist_match\n");
return CL_EMEM;
}
#ifdef USE_MPOOL
((struct regex_matcher *)(engine->whitelist_matcher))->mempool = engine->mempool;
#endif

@ -264,8 +264,10 @@ static int string_assign_concatenated(struct string* dest, const char* prefix, c
{
const size_t prefix_len = strlen(prefix);
char* ret = cli_malloc(prefix_len + end - begin + 1);
if(!ret)
if(!ret) {
cli_errmsg("Phishcheck: Unable to allocate memory for string_assign_concatonated\n");
return CL_EMEM;
}
strncpy(ret, prefix, prefix_len);
strncpy(ret+prefix_len, begin, end-begin);
ret[prefix_len+end-begin]='\0';
@ -278,8 +280,10 @@ static int string_assign_concatenated(struct string* dest, const char* prefix, c
static int string_assign_dup(struct string* dest,const char* start,const char* end)
{
char* ret = cli_malloc(end-start+1);
if(!ret)
if(!ret) {
cli_errmsg("Phishcheck: Unable to allocate memory for string_assign_dup\n");
return CL_EMEM;
}
strncpy(ret,start,end-start);
ret[end-start]='\0';
@ -860,8 +864,10 @@ int phishing_init(struct cl_engine* engine)
struct phishcheck* pchk;
if(!engine->phishcheck) {
pchk = engine->phishcheck = mpool_malloc(engine->mempool, sizeof(struct phishcheck));
if(!pchk)
if(!pchk) {
cli_errmsg("Phishcheck: Unable to allocate memory for initialization\n");
return CL_EMEM;
}
pchk->is_disabled=1;
}
else {

@ -554,8 +554,10 @@ static int cli_loaddb(FILE *fs, struct cl_engine *engine, unsigned int *signo, u
root = engine->root[0];
if(engine->ignored)
if(!(buffer_cpy = cli_malloc(FILEBUFF)))
if(!(buffer_cpy = cli_malloc(FILEBUFF))) {
cli_errmsg("cli_loaddb: Can't allocate memory for buffer_cpy\n");
return CL_EMEM;
}
while(cli_dbgets(buffer, FILEBUFF, fs, dbio)) {
line++;
@ -629,6 +631,7 @@ static int cli_loadidb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
if(engine->ignored)
if(!(buffer_cpy = cli_malloc(FILEBUFF))) {
cli_errmsg("cli_loadidb: CAn't allocate memory for buffer_cpy\n");
mpool_free(engine->mempool, matcher);
return CL_EMEM;
}
@ -903,8 +906,10 @@ static int cli_loadndb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
return ret;
if(engine->ignored)
if(!(buffer_cpy = cli_malloc(FILEBUFF)))
if(!(buffer_cpy = cli_malloc(FILEBUFF))) {
cli_errmsg("cli_loadndb: Can't allocate memory for buffer_cpy\n");
return CL_EMEM;
}
while(cli_dbgets(buffer, FILEBUFF, fs, dbio)) {
line++;
@ -1405,8 +1410,10 @@ static int cli_loadldb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
return ret;
if(engine->ignored)
if(!(buffer_cpy = cli_malloc(sizeof(buffer))))
if(!(buffer_cpy = cli_malloc(sizeof(buffer)))) {
cli_errmsg("cli_loadldb: Can't allocate memory for buffer_cpy\n");
return CL_EMEM;
}
while(cli_dbgets(buffer, sizeof(buffer), fs, dbio)) {
line++;
if(buffer[0] == '#')
@ -1940,8 +1947,10 @@ static int cli_loadhash(FILE *fs, struct cl_engine *engine, unsigned int *signo,
}
if(engine->ignored)
if(!(buffer_cpy = cli_malloc(FILEBUFF)))
if(!(buffer_cpy = cli_malloc(FILEBUFF))) {
cli_errmsg("cli_loadhash: Can't allocate memory for buffer_cpy\n");
return CL_EMEM;
}
while(cli_dbgets(buffer, FILEBUFF, fs, dbio)) {
line++;
@ -2044,8 +2053,10 @@ static int cli_loadmd(FILE *fs, struct cl_engine *engine, unsigned int *signo, i
if(engine->ignored)
if(!(buffer_cpy = cli_malloc(FILEBUFF)))
if(!(buffer_cpy = cli_malloc(FILEBUFF))) {
cli_errmsg("cli_loadmd: Can't allocate memory for buffer_cpy\n");
return CL_EMEM;
}
while(cli_dbgets(buffer, FILEBUFF, fs, dbio)) {
line++;
@ -2197,8 +2208,10 @@ static int cli_loadcdb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
if(engine->ignored)
if(!(buffer_cpy = cli_malloc(FILEBUFF)))
if(!(buffer_cpy = cli_malloc(FILEBUFF))) {
cli_errmsg("cli_loadcdb: Can't allocate memory for buffer_cpy\n");
return CL_EMEM;
}
while(cli_dbgets(buffer, FILEBUFF, fs, dbio)) {
line++;
@ -2734,14 +2747,14 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
if(cli_strbcasestr(dent->d_name, ".ign") || cli_strbcasestr(dent->d_name, ".ign2")) {
dbfile = (char *) cli_malloc(strlen(dent->d_name) + strlen(dirname) + 2);
if(!dbfile) {
cli_dbgmsg("cli_loaddbdir(): dbfile == NULL\n");
cli_errmsg("cli_loaddbdir(): dbfile == NULL\n");
closedir(dd);
return CL_EMEM;
}
sprintf(dbfile, "%s"PATHSEP"%s", dirname, dent->d_name);
ret = cli_load(dbfile, engine, signo, options, NULL);
if(ret) {
cli_dbgmsg("cli_loaddbdir(): error loading database %s\n", dbfile);
cli_errmsg("cli_loaddbdir(): error loading database %s\n", dbfile);
free(dbfile);
closedir(dd);
return ret;
@ -2755,6 +2768,7 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
dbfile = (char *) cli_malloc(strlen(dirname) + 20);
if(!dbfile) {
closedir(dd);
cli_errmsg("cli_loaddbdir: Can't allocate memory for dbfile\n");
return CL_EMEM;
}
@ -2832,14 +2846,14 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
dbfile = (char *) cli_malloc(strlen(dent->d_name) + strlen(dirname) + 2);
if(!dbfile) {
cli_dbgmsg("cli_loaddbdir(): dbfile == NULL\n");
cli_errmsg("cli_loaddbdir(): dbfile == NULL\n");
closedir(dd);
return CL_EMEM;
}
sprintf(dbfile, "%s"PATHSEP"%s", dirname, dent->d_name);
ret = cli_load(dbfile, engine, signo, options, NULL);
if(ret) {
cli_dbgmsg("cli_loaddbdir(): error loading database %s\n", dbfile);
cli_errmsg("cli_loaddbdir(): error loading database %s\n", dbfile);
free(dbfile);
closedir(dd);
return ret;
@ -2964,6 +2978,7 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
#ifdef _WIN32
dbstat->statdname = (char **) cli_realloc2(dbstat->statdname, dbstat->entries * sizeof(char *));
if(!dbstat->statdname) {
cli_errmsg("cl_statinidir: Can't allocate memory for dbstat->statdname\n");
cl_statfree(dbstat);
closedir(dd);
return CL_EMEM;
@ -2972,6 +2987,7 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
fname = cli_malloc(strlen(dirname) + strlen(dent->d_name) + 32);
if(!fname) {
cli_errmsg("cl_statinidir: Cant' allocate memory for fname\n");
cl_statfree(dbstat);
closedir(dd);
return CL_EMEM;
@ -2980,6 +2996,7 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
#ifdef _WIN32
dbstat->statdname[dbstat->entries - 1] = (char *) cli_malloc(strlen(dent->d_name) + 1);
if(!dbstat->statdname[dbstat->entries - 1]) {
cli_errmsg("cli_statinidir: Can't allocate memory for dbstat->statdname\n");
cl_statfree(dbstat);
closedir(dd);
return CL_EMEM;
@ -3036,6 +3053,7 @@ int cl_statchkdir(const struct cl_stat *dbstat)
if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..") && CLI_DBEXT(dent->d_name)) {
fname = cli_malloc(strlen(dbstat->dir) + strlen(dent->d_name) + 32);
if(!fname) {
cli_errmsg("cl_statchkdir: can't allocate memory for fname\n");
closedir(dd);
return CL_EMEM;
}

@ -179,8 +179,10 @@ int regex_list_match(struct regex_matcher* matcher,char* real_url,const char* di
struct cli_ac_data mdata;
struct cli_ac_result *res = NULL;
if(!buffer)
if(!buffer) {
cli_errmsg("regex_list_match: Unable to allocate memory for buffer\n");
return CL_EMEM;
}
strncpy(buffer,real_url,real_len);
buffer[real_len]= (!is_whitelist && hostOnly) ? '/' : ':';
@ -369,6 +371,7 @@ static int add_hash(struct regex_matcher *matcher, char* pattern, const char fl,
pat->virname = mpool_malloc(matcher->mempool, 1);
if(!pat->virname) {
free(pat);
cli_errmsg("add_hash: Unable to allocate memory for path->virname\n");
return CL_EMEM;
}
*pat->virname = fl;
@ -592,6 +595,7 @@ static int add_newsuffix(struct regex_matcher *matcher, struct regex_list *info,
new->pattern = mpool_malloc(matcher->mempool, sizeof(new->pattern[0])*len);
if(!new->pattern) {
mpool_free(matcher->mempool, new);
cli_errmsg("add_newsuffix: Unable to allocate memory for new->pattern\n");
return CL_EMEM;
}
for(i=0;i<len;i++)
@ -629,8 +633,10 @@ static int add_pattern_suffix(void *cbdata, const char *suffix, size_t suffix_le
const struct cli_element *el;
assert(matcher);
if(!regex)
if(!regex) {
cli_errmsg("add_pattern_suffix: Unable to allocate memory for regex\n");
return CL_EMEM;
}
regex->pattern = iregex->pattern ? cli_strdup(iregex->pattern) : NULL;
regex->preg = iregex->preg;
regex->nxt = NULL;
@ -675,11 +681,15 @@ static regex_t *new_preg(struct regex_matcher *matcher)
{
regex_t *r;
matcher->all_pregs = mpool_realloc(matcher->mempool, matcher->all_pregs, ++matcher->regex_cnt * sizeof(*matcher->all_pregs));
if(!matcher->all_pregs)
if(!matcher->all_pregs) {
cli_errmsg("new_preg: Unable to reallocate memory\n");
return NULL;
}
r = mpool_malloc(matcher->mempool, sizeof(*r));
if(!r)
if(!r) {
cli_errmsg("new_preg: Unable to allocate memory\n");
return NULL;
}
matcher->all_pregs[matcher->regex_cnt-1] = r;
return r;
}

@ -78,8 +78,10 @@ static struct node* make_node(enum node_type type, struct node *left, struct nod
return left;
}
n = cli_malloc(sizeof(*n));
if(!n)
if(!n) {
cli_errmsg("make_node: Unable to allocate memory for new node\n");
return NULL;
}
n->type = type;
n->parent = NULL;
n->u.children.left = left;
@ -99,8 +101,10 @@ static struct node *dup_node(struct node *p)
if(!p)
return NULL;
d = cli_malloc(sizeof(*d));
if(!d)
if(!d) {
cli_errmsg("dup_node: Unable to allocate memory for duplicate node\n");
return NULL;
}
d->type = p->type;
d->parent = NULL;
switch(p->type) {
@ -110,6 +114,7 @@ static struct node *dup_node(struct node *p)
case leaf_class:
d->u.leaf_class_bitmap = cli_malloc(32);
if(!d->u.leaf_class_bitmap) {
cli_errmsg("make_node: Unable to allocate memory for leaf class\n");
free(d);
return NULL;
}
@ -132,8 +137,10 @@ static struct node *dup_node(struct node *p)
static struct node *make_charclass(uint8_t *bitmap)
{
struct node *v = cli_malloc(sizeof(*v));
if(!v)
if(!v) {
cli_errmsg("make_charclass: Unable to allocate memory for character class\n");
return NULL;
}
v->type = leaf_class;
v->parent = NULL;
v->u.leaf_class_bitmap = bitmap;
@ -178,8 +185,10 @@ static uint8_t* parse_char_class(const char *pat, size_t *pos)
unsigned char range_start=0;
int hasprev = 0;
uint8_t* bitmap = cli_malloc(32);
if(!bitmap)
if(!bitmap) {
cli_errmsg("parse_char_class: Unable to allocate memory for bitmap\n");
return NULL;
}
if (pat[*pos]=='^') {
memset(bitmap,0xFF,32);/*match chars not in brackets*/
++*pos;

@ -214,8 +214,10 @@ static int load_actions(table_t* t)
static int rtf_object_begin(struct rtf_state* state,cli_ctx* ctx,const char* tmpdir)
{
struct rtf_object_data* data = cli_malloc(sizeof(*data));
if(!data)
if(!data) {
cli_errmsg("rtf_object_begin: Unable to allocate memory for object data\n");
return CL_EMEM;
}
data->fd = -1;
data->partial = 0;
data->has_partial = 0;
@ -329,6 +331,7 @@ static int rtf_object_process(struct rtf_state* state, const unsigned char* inpu
else
data->desc_name = cli_malloc(data->desc_len+1);
if(!data->desc_name) {
cli_errmsg("rtf_object_process: Unable to allocate memory for data->desc_name\n");
return CL_EMEM;
}
data->internal_state = WAIT_DESC;
@ -524,8 +527,10 @@ int cli_scanrtf(cli_ctx *ctx)
stack.warned = 0;
stack.states = cli_malloc(stack.stack_size*sizeof(*stack.states));
if(!stack.states)
if(!stack.states) {
cli_errmsg("ScanRTF: Unable to allocate memory for stack states\n");
return CL_EMEM;
}
if(!(tempname = cli_gentemp(ctx->engine->tmpdir)))
return CL_EMEM;

@ -135,6 +135,7 @@ static int cli_scandir(const char *dirname, cli_ctx *ctx)
fname = cli_malloc(strlen(dirname) + strlen(dent->d_name) + 2);
if(!fname) {
closedir(dd);
cli_dbgmsg("cli_scandir: Unable to allocate memory for filename\n");
return CL_EMEM;
}
@ -1016,6 +1017,7 @@ static int cli_vba_scandir(const char *dirname, cli_ctx *ctx, struct uniq *U)
/* build the full name */
fullname = cli_malloc(strlen(dirname) + strlen(dent->d_name) + 2);
if(!fullname) {
cli_dbgmsg("cli_vba_scandir: Unable to allocate memory for fullname\n");
ret = CL_EMEM;
break;
}

@ -714,6 +714,7 @@ static int real_scansis9x(cli_ctx *ctx, const char *tmpd) {
}
if (!(dst=cli_malloc(uusize))) {
cli_dbgmsg("SIS: OOM\n");
free(src);
break;
}

@ -167,8 +167,10 @@ int unspin(char *src, int ssize, struct cli_exe_section *sections, int sectcnt,
cli_dbgmsg("in unspin\n");
if ((spinned = (char *) cli_malloc(sections[sectcnt].rsz)) == NULL )
if ((spinned = (char *) cli_malloc(sections[sectcnt].rsz)) == NULL ) {
cli_dbgmsg("spin: Unable to allocate memory for spinned\n");
return 1;
}
memcpy(spinned, src + sections[sectcnt].raw, sections[sectcnt].rsz);
ep = spinned + nep - sections[sectcnt].rva;
@ -390,8 +392,10 @@ int unspin(char *src, int ssize, struct cli_exe_section *sections, int sectcnt,
}
cli_dbgmsg("spin: Compression bitmap is %x\n", bitmap);
if ( (sects= (char **) cli_malloc(sectcnt*sizeof(char *))) == NULL )
if ( (sects= (char **) cli_malloc(sectcnt*sizeof(char *))) == NULL ) {
cli_dbgmsg("spin: malloc(%d) failed\n", sectcnt*sizeof(char *));
return 1;
}
len = 0;
for (j=0; j<sectcnt; j++) {
@ -458,6 +462,7 @@ int unspin(char *src, int ssize, struct cli_exe_section *sections, int sectcnt,
}
} else {
/* malloc failed but i'm too deep into this crap to quit without leaking more :( */
cli_dbgmsg("spin: memory allocation failed, continuing anyway\n");
blobsz+=sections[j].rsz;
}
} else {

@ -323,8 +323,10 @@ char *cli_strtok(const char *line, int fieldno, const char *delim)
return NULL;
}
buffer = cli_malloc(j-i+1);
if(!buffer)
return NULL;
if(!buffer) {
cli_errmsg("cli_strtok: Unable to allocate memory for buffer\n");
return NULL;
}
strncpy(buffer, line+i, j-i);
buffer[j-i] = '\0';
@ -497,8 +499,10 @@ char *cli_unescape(const char *str)
/* unescaped string is at most as long as original,
* it will usually be shorter */
R = cli_malloc(len + 1);
if(!R)
if(!R) {
cli_errmsg("cli_unescape: Unable to allocate memory for string\n");
return NULL;
}
for(k=0;k < len;k++) {
unsigned char c = str[k];
if (str[k] == '%') {

@ -103,8 +103,10 @@ tableInsert(table_t *table, const char *key, int value)
(tableEntry *)cli_malloc(sizeof(tableEntry));
}
if(table->tableLast == NULL)
if(table->tableLast == NULL) {
cli_dbgmsg("tableInsert: Unable to allocate memory for table\n");
return -1;
}
table->tableLast->next = NULL;
table->tableLast->key = cli_strdup(key);

@ -146,6 +146,7 @@ textCopy(const text *t_head)
}
if(last == NULL) {
cli_errmsg("textCopy: Unable to allocate memory to clone object\n");
if(first)
textDestroy(first);
return NULL;
@ -247,8 +248,10 @@ textMove(text *t_head, text *t)
return NULL;
}
t_head = (text *)cli_malloc(sizeof(text));
if(t_head == NULL)
if(t_head == NULL) {
cli_errmsg("textMove: Unable to allocate memory for head\n");
return NULL;
}
t_head->t_line = t->t_line;
t_head->t_next = t->t_next;
t->t_line = NULL;
@ -269,8 +272,10 @@ textMove(text *t_head, text *t)
* empty, the rest is moved by a simple pointer reassignment
*/
t_head->t_next = (text *)cli_malloc(sizeof(text));
if(t_head->t_next == NULL)
if(t_head->t_next == NULL) {
cli_errmsg("textMove: Unable to allocate memory for head->next\n");
return NULL;
}
t_head = t_head->t_next;
assert(t_head != NULL);

@ -248,8 +248,10 @@ tnef_message(fmap_t *map, off_t *pos, uint16_t type, uint16_t tag, int32_t lengt
if(length <= 0)
return -1;
string = cli_malloc(length + 1);
if(string == NULL)
if(string == NULL) {
cli_errmsg("tnef_message: Unable to allocate memory for string\n");
return -1;
}
if(fmap_readn(map, string, *pos, (uint32_t)length) != (uint32_t)length) {
free(string);
return -1;
@ -297,8 +299,10 @@ tnef_attachment(fmap_t *map, off_t *pos, uint16_t type, uint16_t tag, int32_t le
if(length <= 0)
return -1;
string = cli_malloc(length + 1);
if(string == NULL)
if(string == NULL) {
cli_errmsg("tnef_attachment: Unable to allocate memory for string\n");
return -1;
}
if(fmap_readn(map, string, *pos, (uint32_t)length) != (uint32_t)length) {
free(string);
return -1;

@ -849,13 +849,17 @@ static int arj_read_main_header(arj_metadata_t *metadata)
}
filename = fmap_need_offstr(metadata->map, metadata->offset, header_size);
if (!filename)
if (!filename) {
cli_dbgmsg("UNARJ: Unable to allocate memory for filename\n");
return FALSE;
}
metadata->offset += strlen(filename) + 1;
comment = fmap_need_offstr(metadata->map, metadata->offset, header_size);
if (!comment)
if (!comment) {
cli_dbgmsg("UNARJ: Unable to allocate memory for comment\n");
return FALSE;
}
metadata->offset += strlen(comment) + 1;
cli_dbgmsg("Filename: %s\n", filename);
cli_dbgmsg("Comment: %s\n", comment);
@ -929,13 +933,17 @@ static int arj_read_file_header(arj_metadata_t *metadata)
}
filename = fmap_need_offstr(metadata->map, metadata->offset, header_size);
if (!filename)
if (!filename) {
cli_dbgmsg("UNARJ: Unable to allocate memory for filename\n");
return FALSE;
}
metadata->offset += strlen(filename) + 1;
comment = fmap_need_offstr(metadata->map, metadata->offset, header_size);
if (!comment)
if (!comment) {
cli_dbgmsg("UNARJ: Unable to allocate memory for comment\n");
return FALSE;
}
metadata->offset += strlen(comment) + 1;
cli_dbgmsg("Filename: %s\n", filename);
cli_dbgmsg("Comment: %s\n", comment);

@ -149,7 +149,10 @@ uint32_t unspack(const char *start_of_stuff, char *dest, cli_ctx *ctx, uint32_t
return 1; /* Should be ~15KB, if it's so big it's prolly just not nspacked */
cli_dbgmsg("unsp: table size = %d\n", tablesz);
if (!(table = cli_malloc(tablesz))) return 1;
if (!(table = cli_malloc(tablesz))) {
cli_dbgmsg("unspack: Unable to allocate memory for table\n");
return 1;
}
dsize = cli_readint32(start_of_stuff+9);
ssize = cli_readint32(start_of_stuff+5);

@ -104,8 +104,10 @@ get_unicode_name(const char *name, int size, int big_endian)
return NULL;
newname = (char *)cli_malloc(size * 7 + 1);
if(newname == NULL)
if(newname == NULL) {
cli_errmsg("get_unicode_name: Unable to allocate memory for newname\n");
return NULL;
}
if((!big_endian) && (size & 0x1)) {
cli_dbgmsg("get_unicode_name: odd number of bytes %d\n", size);
@ -897,8 +899,10 @@ word_read_macro_entry(int fd, macro_info_t *macro_info)
msize = count * sizeof(struct macro);
m = cli_malloc(msize);
if(m == NULL)
if(m == NULL) {
cli_errmsg("word_read_macro_entry: Unable to allocate memory for 'm'\n");
return FALSE;
}
if(cli_readn(fd, m, msize) != msize) {
free(m);
@ -932,6 +936,7 @@ word_read_macro_info(int fd, macro_info_t *macro_info)
macro_info->entries = (macro_entry_t *)cli_malloc(sizeof(macro_entry_t) * macro_info->count);
if(macro_info->entries == NULL) {
macro_info->count = 0;
cli_errmsg("word_read_macro_info: Unable to allocate memory for macro_info->entries\n");
return NULL;
}
if(!word_read_macro_entry(fd, macro_info)) {
@ -1166,6 +1171,7 @@ cli_wm_readdir(int fd)
m++;
}
} else {
cli_errmsg("cli_wm_readdir: Unable to allocate memory for vba_project\n");
free(vba_project->name);
free(vba_project->colls);
free(vba_project->dir);
@ -1195,8 +1201,10 @@ cli_wm_decrypt_macro(int fd, off_t offset, uint32_t len, unsigned char key)
return NULL;
buff = (unsigned char *)cli_malloc(len);
if(buff == NULL)
if(buff == NULL) {
cli_errmsg("cli_wm_decrypt_macro: Unable to allocate memory for buff\n");
return NULL;
}
if(!seekandread(fd, offset, SEEK_SET, buff, len)) {
free(buff);
@ -1284,8 +1292,10 @@ create_vba_project(int record_count, const char *dir, struct uniq *U)
ret = (vba_project_t *) cli_malloc(sizeof(struct vba_project_tag));
if(ret == NULL)
if(ret == NULL) {
cli_errmsg("create_vba_project: Unable to allocate memory for vba project structure\n");
return NULL;
}
ret->name = (char **)cli_malloc(sizeof(char *) * record_count);
ret->colls = (uint32_t *)cli_malloc(sizeof(uint32_t) * record_count);
@ -1302,6 +1312,7 @@ create_vba_project(int record_count, const char *dir, struct uniq *U)
if(ret->offset)
free(ret->offset);
free(ret);
cli_errmsg("create_vba_project: Unable to allocate memory for vba project elements\n");
return NULL;
}
ret->count = record_count;

@ -94,7 +94,10 @@ int wwunpack(uint8_t *exe, uint32_t exesz, uint8_t *wwsect, struct cli_exe_secti
break;
}
cli_dbgmsg("WWP: src: %x, szd: %x, srcend: %x - %x\n", src, szd, srcend, srcend+4-szd);
if (!(compd = cli_malloc(szd))) break;
if (!(compd = cli_malloc(szd))) {
cli_dbgmsg("WWPack: Unable to allocate memory for compd\n");
break;
}
memcpy(compd, unpd, szd);
memset(unpd, -1, szd); /*FIXME*/
ccur=compd;

Loading…
Cancel
Save