... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Fri Aug 6 11:37:14 CEST 2010 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav/elf.c: fix zero mem alloc warning (bb#2173) |
|
4 |
+ |
|
1 | 5 |
Thu Aug 5 11:58:56 CEST 2010 (acab) |
2 | 6 |
------------------------------------ |
3 | 7 |
* win32: fix libclamav's triple and fix GetVersion (bb#2152 and bb#2153) |
... | ... |
@@ -66,8 +66,8 @@ static uint32_t cli_rawaddr(uint32_t vaddr, struct elf_program_hdr32 *ph, uint16 |
66 | 66 |
int cli_scanelf(cli_ctx *ctx) |
67 | 67 |
{ |
68 | 68 |
struct elf_file_hdr32 file_hdr; |
69 |
- struct elf_section_hdr32 *section_hdr; |
|
70 |
- struct elf_program_hdr32 *program_hdr; |
|
69 |
+ struct elf_section_hdr32 *section_hdr = NULL; |
|
70 |
+ struct elf_program_hdr32 *program_hdr = NULL; |
|
71 | 71 |
uint16_t shnum, phnum, shentsize, phentsize; |
72 | 72 |
uint32_t entry, fentry, shoff, phoff, i; |
73 | 73 |
uint8_t conv = 0, err; |
... | ... |
@@ -237,14 +237,15 @@ int cli_scanelf(cli_ctx *ctx) |
237 | 237 |
phoff = EC32(file_hdr.e_phoff, conv); |
238 | 238 |
cli_dbgmsg("ELF: Program header table offset: %d\n", phoff); |
239 | 239 |
|
240 |
- program_hdr = (struct elf_program_hdr32 *) cli_calloc(phnum, phentsize); |
|
241 |
- if(!program_hdr) { |
|
242 |
- cli_errmsg("ELF: Can't allocate memory for program headers\n"); |
|
243 |
- return CL_EMEM; |
|
240 |
+ if(phnum) { |
|
241 |
+ program_hdr = (struct elf_program_hdr32 *) cli_calloc(phnum, phentsize); |
|
242 |
+ if(!program_hdr) { |
|
243 |
+ cli_errmsg("ELF: Can't allocate memory for program headers\n"); |
|
244 |
+ return CL_EMEM; |
|
245 |
+ } |
|
246 |
+ cli_dbgmsg("------------------------------------\n"); |
|
244 | 247 |
} |
245 | 248 |
|
246 |
- cli_dbgmsg("------------------------------------\n"); |
|
247 |
- |
|
248 | 249 |
for(i = 0; i < phnum; i++) { |
249 | 250 |
err = 0; |
250 | 251 |
if(format == 1) { |
... | ... |
@@ -333,14 +334,15 @@ int cli_scanelf(cli_ctx *ctx) |
333 | 333 |
shoff = EC32(file_hdr.e_shoff, conv); |
334 | 334 |
cli_dbgmsg("ELF: Section header table offset: %d\n", shoff); |
335 | 335 |
|
336 |
- section_hdr = (struct elf_section_hdr32 *) cli_calloc(shnum, shentsize); |
|
337 |
- if(!section_hdr) { |
|
338 |
- cli_errmsg("ELF: Can't allocate memory for section headers\n"); |
|
339 |
- return CL_EMEM; |
|
336 |
+ if(shnum) { |
|
337 |
+ section_hdr = (struct elf_section_hdr32 *) cli_calloc(shnum, shentsize); |
|
338 |
+ if(!section_hdr) { |
|
339 |
+ cli_errmsg("ELF: Can't allocate memory for section headers\n"); |
|
340 |
+ return CL_EMEM; |
|
341 |
+ } |
|
342 |
+ cli_dbgmsg("------------------------------------\n"); |
|
340 | 343 |
} |
341 | 344 |
|
342 |
- cli_dbgmsg("------------------------------------\n"); |
|
343 |
- |
|
344 | 345 |
for(i = 0; i < shnum; i++) { |
345 | 346 |
err = 0; |
346 | 347 |
if(format == 1) { |
... | ... |
@@ -458,8 +460,8 @@ int cli_scanelf(cli_ctx *ctx) |
458 | 458 |
int cli_elfheader(fmap_t *map, struct cli_exe_info *elfinfo) |
459 | 459 |
{ |
460 | 460 |
struct elf_file_hdr32 file_hdr; |
461 |
- struct elf_section_hdr32 *section_hdr; |
|
462 |
- struct elf_program_hdr32 *program_hdr; |
|
461 |
+ struct elf_section_hdr32 *section_hdr = NULL; |
|
462 |
+ struct elf_program_hdr32 *program_hdr = NULL; |
|
463 | 463 |
uint16_t shnum, phnum, shentsize, phentsize, i; |
464 | 464 |
uint32_t entry, fentry = 0, shoff, phoff; |
465 | 465 |
uint8_t conv = 0, err; |
... | ... |
@@ -602,12 +604,14 @@ int cli_elfheader(fmap_t *map, struct cli_exe_info *elfinfo) |
602 | 602 |
return -1; |
603 | 603 |
} |
604 | 604 |
|
605 |
- section_hdr = (struct elf_section_hdr32 *) cli_calloc(shnum, shentsize); |
|
606 |
- if(!section_hdr) { |
|
607 |
- cli_errmsg("ELF: Can't allocate memory for section headers\n"); |
|
608 |
- free(elfinfo->section); |
|
609 |
- elfinfo->section = NULL; |
|
610 |
- return -1; |
|
605 |
+ if(shnum) { |
|
606 |
+ section_hdr = (struct elf_section_hdr32 *) cli_calloc(shnum, shentsize); |
|
607 |
+ if(!section_hdr) { |
|
608 |
+ cli_errmsg("ELF: Can't allocate memory for section headers\n"); |
|
609 |
+ free(elfinfo->section); |
|
610 |
+ elfinfo->section = NULL; |
|
611 |
+ return -1; |
|
612 |
+ } |
|
611 | 613 |
} |
612 | 614 |
|
613 | 615 |
for(i = 0; i < shnum; i++) { |