From db89b93b4492e95010618a0018c7179898bedb47 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 29 Jun 2015 14:02:24 +0000 Subject: [PATCH] Convert an assert that can fail into error checking. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240944 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/ELF.h | 3 ++- test/Object/Inputs/invalid-strtab-type.elf | Bin 0 -> 536 bytes test/Object/invalid.test | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 test/Object/Inputs/invalid-strtab-type.elf 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 0000000000000000000000000000000000000000..2a072ebe51d4714f88188da5f0cf598b21cb09ca GIT binary patch literal 536 zcmb<-^>JfjWMpQ50!9Wq21XbMiJpPPb^x;-7}&6?geX)1Q%n#JGO1URT2aEFmsDKL zpjTW{RFaqkq$_j5bV_1LBC=Wv*gQbJ*!)odHB$-AY;?6CJ_xg+sdGT%!?-Lk29%Zo z(jfitfQ5=XKxuReT|YZe0S6G1t6v1D7fa|fH~_^#zyLyl-3U?#vI_(xAQS@tHqsB< literal 0 HcmV?d00001 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 -- 2.34.1