}
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 {
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);
}
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