From d35771292e99dae6db6d9e5fdd530b0152b51c1b Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Sun, 27 Apr 2014 16:41:47 -0500 Subject: [PATCH] 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 --- simavr/sim/sim_elf.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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); -- 2.39.5