~ubuntu-branches/ubuntu/jaunty/clamav/jaunty-backports

« back to all changes in this revision

Viewing changes to libclamav/elf.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-10-02 17:11:00 UTC
  • mfrom: (0.3.1 lucid-proposed)
  • Revision ID: james.westby@ubuntu.com-20101002171100-0erjjoucua6kw2pc
Tags: 0.96.3+dfsg-2ubuntu0.10.04.1~jaunty1
* Source backport for Jaunty
  - Change build-dep on libtdl-dev to libtdl7-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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
334
    shoff = EC32(file_hdr.e_shoff, conv);
334
335
    cli_dbgmsg("ELF: Section header table offset: %d\n", shoff);
335
336
 
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;
 
337
    if(shnum) {
 
338
        section_hdr = (struct elf_section_hdr32 *) cli_calloc(shnum, shentsize);
 
339
        if(!section_hdr) {
 
340
            cli_errmsg("ELF: Can't allocate memory for section headers\n");
 
341
            return CL_EMEM;
 
342
        }
 
343
        cli_dbgmsg("------------------------------------\n");
340
344
    }
341
345
 
342
 
    cli_dbgmsg("------------------------------------\n");
343
 
 
344
346
    for(i = 0; i < shnum; i++) {
345
347
        err = 0;
346
348
        if(format == 1) {
458
460
int cli_elfheader(fmap_t *map, struct cli_exe_info *elfinfo)
459
461
{
460
462
        struct elf_file_hdr32 file_hdr;
461
 
        struct elf_section_hdr32 *section_hdr;
462
 
        struct elf_program_hdr32 *program_hdr;
 
463
        struct elf_section_hdr32 *section_hdr = NULL;
 
464
        struct elf_program_hdr32 *program_hdr = NULL;
463
465
        uint16_t shnum, phnum, shentsize, phentsize, i;
464
466
        uint32_t entry, fentry = 0, shoff, phoff;
465
467
        uint8_t conv = 0, err;
602
604
        return -1;
603
605
    }
604
606
 
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;
 
607
    if(shnum) {
 
608
        section_hdr = (struct elf_section_hdr32 *) cli_calloc(shnum, shentsize);
 
609
        if(!section_hdr) {
 
610
            cli_errmsg("ELF: Can't allocate memory for section headers\n");
 
611
            free(elfinfo->section);
 
612
            elfinfo->section = NULL;
 
613
            return -1;
 
614
        }
611
615
    }
612
616
 
613
617
    for(i = 0; i < shnum; i++) {