Commit d35771292e99dae6db6d9e5fdd530b0152b51c1b
authorDoug Goldstein <cardoe@cardoe.com>
Sun, 27 Apr 2014 21:41:47 +0000 (16:41 -0500)
committerMichel Pollet <michel.pollet@bp.renesas.com>
Wed, 19 Oct 2016 09:12:41 +0000 (10:12 +0100)
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

index 529c2dfb11077a82e73f15b3f348b63aa06e9dfd..3d01110956c498ad8e59ee48371a5724f32c6bfc 100644 (file)
@@ -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);