From 7206f5bd06108590680f9f2bc941a8588bd022ed Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 9 May 2020 20:34:25 -0700 Subject: [PATCH] libbacktrace: don't crash if ELF file has no sections Patch from Roland McGrath. Fixes #41 --- elf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/elf.c b/elf.c index 1216af8..80a0050 100644 --- a/elf.c +++ b/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. */