From: Doug Goldstein Date: Sun, 27 Apr 2014 21:41:47 +0000 (-0500) Subject: elf: check for error instead of crashing X-Git-Tag: v1.4~15 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=d35771292e99dae6db6d9e5fdd530b0152b51c1b;p=sx%2Fsimavr.git elf: check for error instead of crashing Check for error when allocating memory instead of dereferencing a NULL pointer later in the program. (cherry picked from commit b3ecaf43cba921c6a257132093107771074ab749) Conflicts: simavr/sim/sim_elf.c --- diff --git a/simavr/sim/sim_elf.c b/simavr/sim/sim_elf.c index 529c2df..3d01110 100644 --- a/simavr/sim/sim_elf.c +++ b/simavr/sim/sim_elf.c @@ -374,16 +374,19 @@ int elf_read_firmware(const char * file, elf_firmware_t * firmware) firmware->datasize = data_data->d_size; } if (data_ee) { - elf_copy_section(".eeprom", data_ee, &firmware->eeprom); + if (elf_copy_section(".eeprom", data_ee, &firmware->eeprom)) + return -1; firmware->eesize = data_ee->d_size; } if (data_fuse) { - elf_copy_section(".fuse", data_fuse, &firmware->fuse); - firmware->fusesize = data_fuse->d_size; + if (elf_copy_section(".fuse", data_fuse, &firmware->fuse)) + return -1; + firmware->fusesize = data_fuse->d_size; + } + if (data_lockbits) { + if (elf_copy_section(".lock", data_fuse, &firmware->lockbits)) + return -1; } - if (data_lockbits) - elf_copy_section(".lock", data_fuse, &firmware->lockbits); - // hdump("flash", avr->flash, offset); elf_end(elf); close(fd);