From: George Rimar Date: Thu, 27 Oct 2016 11:41:57 +0000 (+0000) Subject: [Object/ELF] - Do not crash if string table sh_size is equal to zero. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2bbde38ea6f99c814405544d13de4ca3e9f997d4;p=llvm [Object/ELF] - Do not crash if string table sh_size is equal to zero. Revealed using "id_000038,sig_11,src_000015,op_havoc,rep_16" from PR30540, when sh_size was 0, crash happened. Differential revision: https://reviews.llvm.org/D25091 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285282 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 7aee6b17574..b6d4b804c27 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -428,6 +428,8 @@ ELFFile::getStringTable(const Elf_Shdr *Section) const { if (std::error_code EC = V.getError()) return EC; ArrayRef Data = *V; + if (Data.empty()) + return object_error::parse_failed; if (Data.back() != '\0') return object_error::string_table_non_null_end; return StringRef(Data.begin(), Data.size()); diff --git a/test/Object/Inputs/invalid-strtab-zero-size.elf b/test/Object/Inputs/invalid-strtab-zero-size.elf new file mode 100644 index 00000000000..cb0d0d0d0f9 Binary files /dev/null and b/test/Object/Inputs/invalid-strtab-zero-size.elf differ diff --git a/test/Object/invalid.test b/test/Object/invalid.test index fda5d6d66d6..352917987de 100644 --- a/test/Object/invalid.test +++ b/test/Object/invalid.test @@ -1,6 +1,7 @@ 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 RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-size.elf 2>&1 | FileCheck %s +RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-zero-size.elf 2>&1 | FileCheck %s CHECK: Invalid data was encountered while parsing the file RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-non-null.elf 2>&1 | FileCheck --check-prefix=NON-NULL %s