From: Ian Lance Taylor Date: Sun, 10 May 2020 03:34:25 +0000 (-0700) Subject: libbacktrace: don't crash if ELF file has no sections X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ef6394205d7bcab00dca01182d708ad5a6360a7b;p=gcc.git libbacktrace: don't crash if ELF file has no sections libbacktrace/ * elf.c (elf_add): Bail early if there are no section headers at all. --- diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index 13d907011d8..88dee9983d3 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,3 +1,7 @@ +2020-05-09 Roland McGrath + + * elf.c (elf_add): Bail early if there are no section headers at all. + 2020-05-09 Ian Lance Taylor * elf.c (elf_add): Don't free strtab if an error occurs after diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c index 1216af86fd9..80a00506bd6 100644 --- a/libbacktrace/elf.c +++ b/libbacktrace/elf.c @@ -2781,6 +2781,9 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, backtrace_release_view (state, &shdr_view, error_callback, data); } + if (shnum == 0 || shstrndx == 0) + goto fail; + /* To translate PC to file/line when using DWARF, we need to find the .debug_info and .debug_line sections. */