llvm.org GIT mirror llvm / 850ecab
Report an error if a SHT_SYMTAB_SHNDX section has the wrong size. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245873 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
3 changed file(s) with 23 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
196196
197197 uint64_t getNumSections() const;
198198 uintX_t getStringTableIndex() const;
199 ELF::Elf64_Word
200 getExtendedSymbolTableIndex(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
201 ArrayRef ShndxTable) const;
199 uint32_t getExtendedSymbolTableIndex(const Elf_Sym *Sym,
200 const Elf_Shdr *SymTab,
201 ArrayRef ShndxTable) const;
202202 const Elf_Ehdr *getHeader() const { return Header; }
203203 ErrorOr getSection(const Elf_Sym *Sym,
204204 const Elf_Shdr *SymTab,
219219 typedef ELFFile> ELF64BEFile;
220220
221221 template
222 ELF::Elf64_Word ELFFile::getExtendedSymbolTableIndex(
222 uint32_t ELFFile::getExtendedSymbolTableIndex(
223223 const Elf_Sym *Sym, const Elf_Shdr *SymTab,
224224 ArrayRef ShndxTable) const {
225225 assert(Sym->st_shndx == ELF::SHN_XINDEX);
226226 unsigned Index = Sym - symbol_begin(SymTab);
227227
228 // FIXME: error checking
228 // The size of the table was checked in getSHNDXTable.
229229 return ShndxTable[Index];
230230 }
231231
470470 assert(Section.sh_type == ELF::SHT_SYMTAB_SHNDX);
471471 const Elf_Word *ShndxTableBegin =
472472 reinterpret_cast(base() + Section.sh_offset);
473 uintX_t Size = Section.sh_offset;
474 if (Size % sizeof(uintX_t))
475 return object_error::parse_failed;
476 const Elf_Word *ShndxTableEnd = ShndxTableBegin + Size / sizeof(uintX_t);
473 uintX_t Size = Section.sh_size;
474 if (Size % sizeof(uint32_t))
475 return object_error::parse_failed;
476 uintX_t NumSymbols = Size / sizeof(uint32_t);
477 const Elf_Word *ShndxTableEnd = ShndxTableBegin + NumSymbols;
477478 if (reinterpret_cast(ShndxTableEnd) > Buf.end())
479 return object_error::parse_failed;
480 ErrorOr SymTableOrErr = getSection(Section.sh_link);
481 if (std::error_code EC = SymTableOrErr.getError())
482 return EC;
483 const Elf_Shdr &SymTable = **SymTableOrErr;
484 if (SymTable.sh_type != ELF::SHT_SYMTAB &&
485 SymTable.sh_type != ELF::SHT_DYNSYM)
486 return object_error::parse_failed;
487 if (NumSymbols != (SymTable.sh_size / sizeof(Elf_Sym)))
478488 return object_error::parse_failed;
479489 return ArrayRef(ShndxTableBegin, ShndxTableEnd);
480490 }
4747
4848 RUN: not llvm-readobj -t %p/Inputs/invalid-symbol-table-size.elf 2>&1 | FileCheck --check-prefix=INVALID-SYMTAB-SIZE %s
4949 INVALID-SYMTAB-SIZE: Invalid symbol table size
50
51
52 RUN: not llvm-readobj -t %p/Inputs/invalid-xindex-size.elf 2>&1 | FileCheck --check-prefix=INVALID-XINDEX-SIZE %s
53 INVALID-XINDEX-SIZE: Invalid data was encountered while parsing the file.