diff mbox series

libbacktrace patch committed: Don't crash if no section headers

Message ID CAOyqgcWCc_uUKtMDDQVoPJ1PezZP2De+FyOFYCmQ+efGZbrDJA@mail.gmail.com
State New
Headers show
Series libbacktrace patch committed: Don't crash if no section headers | expand

Commit Message

Ian Lance Taylor May 10, 2020, 3:35 a.m. UTC
This patch to libbacktrace, by Roland McGrath, avoids crashing if an
ELF file has no section headers.  Bootstrapped and ran libbacktrace
testsuite on x86_64-pc-linux-gnu.  This fixes
https://github.com/ianlancetaylor/libbacktrace/issues/41.  Committed
to master.

Ian

2020-05-09  Roland McGrath  <mcgrathr@google.com>

* elf.c (elf_add): Bail early if there are no section headers at all.
diff mbox series

Patch

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.  */