[llvm] r283455 - Centralize sh_entsize checking.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 6 08:08:11 PDT 2016
Author: rafael
Date: Thu Oct 6 10:08:10 2016
New Revision: 283455
URL: http://llvm.org/viewvc/llvm-project?rev=283455&view=rev
Log:
Centralize sh_entsize checking.
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=283455&r1=283454&r2=283455&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Thu Oct 6 10:08:10 2016
@@ -118,8 +118,6 @@ public:
Elf_Sym_Range symbols(const Elf_Shdr *Sec) const {
if (!Sec)
return makeArrayRef<Elf_Sym>(nullptr, nullptr);
- if (Sec->sh_entsize != sizeof(Elf_Sym))
- report_fatal_error("Invalid symbol size");
auto V = getSectionContentsAsArray<Elf_Sym>(Sec);
if (!V)
report_fatal_error(V.getError().message());
@@ -127,8 +125,6 @@ public:
}
Elf_Rela_Range relas(const Elf_Shdr *Sec) const {
- if (Sec->sh_entsize != sizeof(Elf_Rela))
- report_fatal_error("Invalid relocation entry size");
auto V = getSectionContentsAsArray<Elf_Rela>(Sec);
if (!V)
report_fatal_error(V.getError().message());
@@ -136,8 +132,6 @@ public:
}
Elf_Rel_Range rels(const Elf_Shdr *Sec) const {
- if (Sec->sh_entsize != sizeof(Elf_Rel))
- report_fatal_error("Invalid relocation entry size");
auto V = getSectionContentsAsArray<Elf_Rel>(Sec);
if (!V)
report_fatal_error(V.getError().message());
@@ -224,6 +218,9 @@ template <class ELFT>
template <typename T>
ErrorOr<ArrayRef<T>>
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
+ if (Sec->sh_entsize != sizeof(T) && sizeof(T) != 1)
+ return object_error::parse_failed;
+
uintX_t Offset = Sec->sh_offset;
uintX_t Size = Sec->sh_size;
Modified: llvm/trunk/test/Object/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/invalid.test?rev=283455&r1=283454&r2=283455&view=diff
==============================================================================
--- llvm/trunk/test/Object/invalid.test (original)
+++ llvm/trunk/test/Object/invalid.test Thu Oct 6 10:08:10 2016
@@ -35,7 +35,7 @@ SECTION-NEXT: AddressAlignment:
SECTION-NEXT: EntrySize: 32
RUN: not llvm-readobj -t %p/Inputs/invalid-sh_entsize.elf 2>&1 | FileCheck --check-prefix=INVALID-SYM-SIZE %s
-INVALID-SYM-SIZE: Invalid symbol size
+INVALID-SYM-SIZE: Invalid data was encountered while parsing the file
RUN: not llvm-readobj --dyn-symbols %p/Inputs/invalid-sh_entsize.elf 2>&1 | FileCheck --check-prefix=INVALID-DYNSYM-SIZE %s
INVALID-DYNSYM-SIZE: Invalid entity size
More information about the llvm-commits
mailing list