diff options
author | Christian Hoff <christian.hoff@advantest.com> | 2021-04-20 19:14:30 +0200 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2021-05-01 13:36:28 +0100 |
commit | 565129119f0dc345a6e7d16bb468ff15cb3b828d (patch) | |
tree | 91066164ea522f707a20801f615782ecb26fc875 /src/target | |
parent | 9206bd243b0b594821ca96b37517b2e3de80dc39 (diff) | |
download | riscv-openocd-565129119f0dc345a6e7d16bb468ff15cb3b828d.zip riscv-openocd-565129119f0dc345a6e7d16bb468ff15cb3b828d.tar.gz riscv-openocd-565129119f0dc345a6e7d16bb468ff15cb3b828d.tar.bz2 |
target/image: report error if ELF file contains no loadable sections
The existing code asserted in that case, which is not correct. This
would allow the user to crash OpenOCD with a bad ELF file, which is
not what we want. A proper error should be reported in that case and
OpenOCD should not crash.
Change-Id: Ied5a6a6fd4ee0fd163f3fe850d304a121ecbe33a
Signed-off-by: Christian Hoff <christian.hoff@advantest.com>
Reviewed-on: http://openocd.zylin.com/6172
Reviewed-by: Jonathan McDowell <noodles-openocd@earth.li>
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'src/target')
-rw-r--r-- | src/target/image.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/target/image.c b/src/target/image.c index 9608375..8f72329 100644 --- a/src/target/image.c +++ b/src/target/image.c @@ -426,7 +426,10 @@ static int image_elf32_read_headers(struct image *image) (field32(elf, elf->segments32[i].p_filesz) != 0)) image->num_sections++; - assert(image->num_sections > 0); + if (image->num_sections == 0) { + LOG_ERROR("invalid ELF file, no loadable segments"); + return ERROR_IMAGE_FORMAT_ERROR; + } /** * some ELF linkers produce binaries with *all* the program header @@ -548,7 +551,10 @@ static int image_elf64_read_headers(struct image *image) (field64(elf, elf->segments64[i].p_filesz) != 0)) image->num_sections++; - assert(image->num_sections > 0); + if (image->num_sections == 0) { + LOG_ERROR("invalid ELF file, no loadable segments"); + return ERROR_IMAGE_FORMAT_ERROR; + } /** * some ELF linkers produce binaries with *all* the program header |