Report errors an invalid virtual addresses.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242676 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2015-07-20 14:45:03 +00:00
parent 3c7642e230
commit 96d9043a78
3 changed files with 12 additions and 2 deletions

View File

@ -738,9 +738,13 @@ template <class ELFT> void ELFFile<ELFT>::scanDynamicTable() {
const Elf_Phdr **I = std::upper_bound(
LoadSegments.begin(), LoadSegments.end(), VAddr, compareAddr<ELFT>);
if (I == LoadSegments.begin())
return nullptr;
report_fatal_error("Virtual address is not in any segment");
--I;
return this->base() + (*I)->p_offset + (VAddr - (*I)->p_vaddr);
const Elf_Phdr &Phdr = **I;
uint64_t Delta = VAddr - Phdr.p_vaddr;
if (Delta >= Phdr.p_filesz)
report_fatal_error("Virtual address is not in any segment");
return this->base() + Phdr.p_offset + Delta;
};
for (Elf_Dyn_Iter DynI = dynamic_table_begin(), DynE = dynamic_table_end();

Binary file not shown.

View File

@ -37,3 +37,9 @@ RUN: %p/Inputs/corrupt-invalid-phentsize.elf.x86-64 2>&1 | \
RUN: FileCheck --check-prefix=PHENTSIZE %s
PHENTSIZE: Invalid program header size
RUN: not llvm-readobj -dynamic-table \
RUN: %p/Inputs/corrupt-invalid-virtual-addr.elf.x86-64 2>&1 | \
RUN: FileCheck --check-prefix=VIRTADDR %s
VIRTADDR: Virtual address is not in any segment