]> granicus.if.org Git - llvm/commitdiff
Centralize sh_entsize checking.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 6 Oct 2016 15:08:10 +0000 (15:08 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 6 Oct 2016 15:08:10 +0000 (15:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283455 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/ELF.h
test/Object/invalid.test

index fceb0a19f80403832c1c8364698d8b5ffa177b8f..c06fa75231b1915fc1679db33823cd5b44a6e05c 100644 (file)
@@ -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;
 
index 774aa4776b5ccd1764ecbb0684c313169c1e90ed..9f5587422d1e40b4034f0094db2e5027fc810e78 100644 (file)
@@ -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