Report an error on invalid sh_entsize.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241070 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2015-06-30 14:59:20 +00:00
parent f8b3b92eb8
commit e8ff062325
3 changed files with 43 additions and 8 deletions

View File

@ -285,17 +285,18 @@ public:
}
const Elf_Sym *begin_dynamic_symbols() const {
if (DynSymRegion.Addr)
return reinterpret_cast<const Elf_Sym *>(DynSymRegion.Addr);
return nullptr;
if (!DynSymRegion.Addr)
return nullptr;
if (DynSymRegion.EntSize != sizeof(Elf_Sym))
report_fatal_error("Invalid symbol size");
return reinterpret_cast<const Elf_Sym *>(DynSymRegion.Addr);
}
const Elf_Sym *end_dynamic_symbols() const {
if (DynSymRegion.Addr)
return reinterpret_cast<const Elf_Sym *>(
((const char *)DynSymRegion.Addr + DynSymRegion.Size));
return nullptr;
if (!DynSymRegion.Addr)
return nullptr;
return reinterpret_cast<const Elf_Sym *>(
((const char *)DynSymRegion.Addr + DynSymRegion.Size));
}
Elf_Sym_Range dynamic_symbols() const {
@ -766,6 +767,8 @@ template <class ELFT>
const typename ELFFile<ELFT>::Elf_Sym *ELFFile<ELFT>::begin_symbols() const {
if (!dot_symtab_sec)
return nullptr;
if (dot_symtab_sec->sh_entsize != sizeof(Elf_Sym))
report_fatal_error("Invalid symbol size");
return reinterpret_cast<const Elf_Sym *>(base() + dot_symtab_sec->sh_offset);
}

Binary file not shown.

View File

@ -5,3 +5,35 @@ 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
NON-NULL: String table must end with a null terminator
Test the sh_entsize are invalid
RUN: llvm-readobj -s %p/Inputs/invalid-sh_entsize.elf | FileCheck --check-prefix=SECTION %s
SECTION: Name: .dynsym
SECTION-NEXT: Type: SHT_DYNSYM
SECTION-NEXT: Flags [
SECTION-NEXT: SHF_ALLOC
SECTION-NEXT: ]
SECTION-NEXT: Address:
SECTION-NEXT: Offset:
SECTION-NEXT: Size:
SECTION-NEXT: Link:
SECTION-NEXT: Info:
SECTION-NEXT: AddressAlignment:
SECTION-NEXT: EntrySize: 32
SECTION: Name: .symtab
SECTION-NEXT: Type: SHT_SYMTAB
SECTION-NEXT: Flags [
SECTION-NEXT: ]
SECTION-NEXT: Address:
SECTION-NEXT: Offset:
SECTION-NEXT: Size:
SECTION-NEXT: Link:
SECTION-NEXT: Info:
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
RUN: not llvm-readobj --dyn-symbols %p/Inputs/invalid-sh_entsize.elf 2>&1 | FileCheck --check-prefix=INVALID-SYM-SIZE %s
INVALID-SYM-SIZE: Invalid symbol size