Convert an assert that can fail into error checking.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 29 Jun 2015 14:02:24 +0000 (14:02 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 29 Jun 2015 14:02:24 +0000 (14:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240944 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/ELF.h
test/Object/Inputs/invalid-strtab-type.elf [new file with mode: 0644]
test/Object/invalid.test

index ed8ce5aea740bad972556fb4ee78147babe8c411..662057a40b57e70fbd2b8439758639afef798db9 100644 (file)
@@ -867,7 +867,8 @@ ELFFile<ELFT>::getSection(uint32_t index) const {
 template <class ELFT>
 ErrorOr<StringRef> ELFFile<ELFT>::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 (file)
index 0000000..2a072eb
Binary files /dev/null and b/test/Object/Inputs/invalid-strtab-type.elf differ
index 73bf62a1ed4ed6a53d959d02a9eb85adf1b379a8..2e2c924dfaeff0ddfb669a79bcbc26756bda79a9 100644 (file)
@@ -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