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

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 20 01:03:10 PDT 2016


Author: grimar
Date: Thu Oct 20 03:03:10 2016
New Revision: 284702

URL: http://llvm.org/viewvc/llvm-project?rev=284702&view=rev
Log:
[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

Modified:
    llvm/trunk/include/llvm/Object/ELF.h

Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=284702&r1=284701&r2=284702&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Thu Oct 20 03:03:10 2016
@@ -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;




More information about the llvm-commits mailing list