From 62d927241962ad40f3bca9fa3841edf9d7a56b5f Mon Sep 17 00:00:00 2001 From: Sim Sun Date: Fri, 14 Aug 2020 21:36:30 -0700 Subject: [PATCH] linux: Fix segfault when there is no section header in ELF file Some vendor library doesn't contain the section header. It causes segmentation fault in `FindElfClassSection`. > e_shoff: > This member holds the section header table's file offset in bytes. > If the file has no section header table this member holds zero. Change-Id: Id98d6ff3bd16af4541deb5a55a8fad2fa74eda23 Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/2354427 Reviewed-by: Mark Mentovai --- src/common/linux/elfutils.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/common/linux/elfutils.cc b/src/common/linux/elfutils.cc index ce9e9c1c..aa95357a 100644 --- a/src/common/linux/elfutils.cc +++ b/src/common/linux/elfutils.cc @@ -57,6 +57,12 @@ void FindElfClassSection(const char* elf_base, const Ehdr* elf_header = reinterpret_cast(elf_base); assert(elf_header->e_ident[EI_CLASS] == ElfClass::kClass); + if (elf_header->e_shoff == 0) { + *section_start = NULL; + *section_size = 0; + return; + } + const Shdr* sections = GetOffset(elf_header, elf_header->e_shoff); const Shdr* section_names = sections + elf_header->e_shstrndx;