diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index ed8ce5aea74..662057a40b5 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -867,7 +867,8 @@ ELFFile::getSection(uint32_t index) const { template ErrorOr ELFFile::getString(const Elf_Shdr *Section, ELF::Elf32_Word Offset) const { - assert(Section && Section->sh_type == ELF::SHT_STRTAB && "Invalid section!"); + if (Section->sh_type != ELF::SHT_STRTAB) + return object_error::parse_failed; if (Offset >= Section->sh_size) return object_error::parse_failed; return StringRef((const char *)base() + Section->sh_offset + Offset); diff --git a/test/Object/Inputs/invalid-strtab-type.elf b/test/Object/Inputs/invalid-strtab-type.elf new file mode 100644 index 00000000000..2a072ebe51d Binary files /dev/null and b/test/Object/Inputs/invalid-strtab-type.elf differ diff --git a/test/Object/invalid.test b/test/Object/invalid.test index 73bf62a1ed4..2e2c924dfae 100644 --- a/test/Object/invalid.test +++ b/test/Object/invalid.test @@ -1,2 +1,3 @@ RUN: not llvm-dwarfdump %p/Inputs/invalid-bad-rel-type.elf 2>&1 | FileCheck %s +RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-type.elf 2>&1 | FileCheck %s CHECK: Invalid data was encountered while parsing the file