[Object/ELF] - Check index argument in getSymbol().

Without this check LLD crashes when SHT_GROUP section has invalid symbol index
because of next code:

template <class ELFT>
StringRef elf::ObjectFile<ELFT>::getShtGroupSignature(const Elf_Shdr &Sec) {
..
  const Elf_Sym *Sym = Obj.getSymbol(Symtab, Sec.sh_info);
..
}
If sh_info is too large, &Symbols[Index] just asserts.

No testcases provided because llvm-objdump/llvm-readelf does 
not use getSymbol() function.

I`ll commit testcase for LLD separatelly.

Differential revision: https://reviews.llvm.org/D25516

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284702 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
George Rimar 2016-10-20 08:03:10 +00:00
parent f43c9c6d35
commit 3e0be6fc22

View File

@ -168,7 +168,10 @@ public:
ErrorOr<const Elf_Shdr *> getSection(uint32_t Index) const;
const Elf_Sym *getSymbol(const Elf_Shdr *Sec, uint32_t Index) const {
return &symbols(Sec)[Index];
Elf_Sym_Range Symbols = symbols(Sec);
if (Index >= Symbols.size())
report_fatal_error("Invalid symbol index");
return &Symbols[Index];
}
ErrorOr<StringRef> getSectionName(const Elf_Shdr *Section) const;