diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 54d2fa1a583..b7ae0012177 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -168,7 +168,10 @@ public: ErrorOr 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 getSectionName(const Elf_Shdr *Section) const;