[llvm] r284387 - [Object/ELF] - Check Header->e_shoff value earlier and do not crash.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 17 07:28:12 PDT 2016
Author: grimar
Date: Mon Oct 17 09:28:12 2016
New Revision: 284387
URL: http://llvm.org/viewvc/llvm-project?rev=284387&view=rev
Log:
[Object/ELF] - Check Header->e_shoff value earlier and do not crash.
Patch checks that section pointer is aligned properly.
This should be done before getStringTable() call.
Differential revision: https://reviews.llvm.org/D25462
Added:
llvm/trunk/test/Object/Inputs/invalid-sections-address-alignment.x86-64
- copied unchanged from r283857, llvm/trunk/test/Object/Inputs/invalid-sections-address-alignment.x86-64
Modified:
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/test/Object/invalid.test
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=284387&r1=284386&r2=284387&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Mon Oct 17 09:28:12 2016
@@ -334,6 +334,12 @@ ELFFile<ELFT>::ELFFile(StringRef Object,
return;
}
+ if (SectionTableOffset & (AlignOf<Elf_Shdr>::Alignment - 1)) {
+ // Invalid address alignment of section headers
+ EC = object_error::parse_failed;
+ return;
+ }
+
// The getNumSections() call below depends on SectionHeaderTable being set.
SectionHeaderTable =
reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset);
Modified: llvm/trunk/test/Object/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/invalid.test?rev=284387&r1=284386&r2=284387&view=diff
==============================================================================
--- llvm/trunk/test/Object/invalid.test (original)
+++ llvm/trunk/test/Object/invalid.test Mon Oct 17 09:28:12 2016
@@ -67,3 +67,7 @@ RUN: FileCheck --check-prefix=INVALID-
RUN: not llvm-readobj -r %p/Inputs/invalid-relocation-sec-sh_offset.elf-x86-64 2>&1 | \
RUN: FileCheck --check-prefix=INVALID-RELOC-SH-OFFSET %s
INVALID-RELOC-SH-OFFSET: Invalid data was encountered while parsing the file
+
+RUN: not llvm-readobj -t %p/Inputs/invalid-sections-address-alignment.x86-64 2>&1 | \
+RUN: FileCheck --check-prefix=INVALID-SEC-ADDRESS-ALIGNMENT %s
+INVALID-SEC-ADDRESS-ALIGNMENT: Invalid data was encountered while parsing the file
More information about the llvm-commits
mailing list