From ddec8ab4d71d6e391252368951bdb0e9f4540192 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 6 Oct 2016 15:08:10 +0000 Subject: [PATCH] Centralize sh_entsize checking. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283455 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/ELF.h | 9 +++------ test/Object/invalid.test | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index fceb0a19f80..c06fa75231b 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -118,8 +118,6 @@ public: Elf_Sym_Range symbols(const Elf_Shdr *Sec) const { if (!Sec) return makeArrayRef(nullptr, nullptr); - if (Sec->sh_entsize != sizeof(Elf_Sym)) - report_fatal_error("Invalid symbol size"); auto V = getSectionContentsAsArray(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(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(Sec); if (!V) report_fatal_error(V.getError().message()); @@ -224,6 +218,9 @@ template template ErrorOr> ELFFile::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; diff --git a/test/Object/invalid.test b/test/Object/invalid.test index 774aa4776b5..9f5587422d1 100644 --- a/test/Object/invalid.test +++ b/test/Object/invalid.test @@ -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 -- 2.50.0