uint64_t getNumSections() const;
uintX_t getStringTableIndex() const;
- ELF::Elf64_Word
- getExtendedSymbolTableIndex(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
- ArrayRef<Elf_Word> ShndxTable) const;
+ uint32_t getExtendedSymbolTableIndex(const Elf_Sym *Sym,
+ const Elf_Shdr *SymTab,
+ ArrayRef<Elf_Word> ShndxTable) const;
const Elf_Ehdr *getHeader() const { return Header; }
ErrorOr<const Elf_Shdr *> getSection(const Elf_Sym *Sym,
const Elf_Shdr *SymTab,
typedef ELFFile<ELFType<support::big, true>> ELF64BEFile;
template <class ELFT>
-ELF::Elf64_Word ELFFile<ELFT>::getExtendedSymbolTableIndex(
+uint32_t ELFFile<ELFT>::getExtendedSymbolTableIndex(
const Elf_Sym *Sym, const Elf_Shdr *SymTab,
ArrayRef<Elf_Word> ShndxTable) const {
assert(Sym->st_shndx == ELF::SHN_XINDEX);
unsigned Index = Sym - symbol_begin(SymTab);
- // FIXME: error checking
+ // The size of the table was checked in getSHNDXTable.
return ShndxTable[Index];
}
assert(Section.sh_type == ELF::SHT_SYMTAB_SHNDX);
const Elf_Word *ShndxTableBegin =
reinterpret_cast<const Elf_Word *>(base() + Section.sh_offset);
- uintX_t Size = Section.sh_offset;
- if (Size % sizeof(uintX_t))
+ uintX_t Size = Section.sh_size;
+ if (Size % sizeof(uint32_t))
return object_error::parse_failed;
- const Elf_Word *ShndxTableEnd = ShndxTableBegin + Size / sizeof(uintX_t);
+ uintX_t NumSymbols = Size / sizeof(uint32_t);
+ const Elf_Word *ShndxTableEnd = ShndxTableBegin + NumSymbols;
if (reinterpret_cast<const char *>(ShndxTableEnd) > Buf.end())
return object_error::parse_failed;
+ ErrorOr<const Elf_Shdr *> SymTableOrErr = getSection(Section.sh_link);
+ if (std::error_code EC = SymTableOrErr.getError())
+ return EC;
+ const Elf_Shdr &SymTable = **SymTableOrErr;
+ if (SymTable.sh_type != ELF::SHT_SYMTAB &&
+ SymTable.sh_type != ELF::SHT_DYNSYM)
+ return object_error::parse_failed;
+ if (NumSymbols != (SymTable.sh_size / sizeof(Elf_Sym)))
+ return object_error::parse_failed;
return ArrayRef<Elf_Word>(ShndxTableBegin, ShndxTableEnd);
}