Skip to content

Commit

Permalink
Report errors an invalid virtual addresses.
Browse files Browse the repository at this point in the history
llvm-svn: 242676
  • Loading branch information
espindola committed Jul 20, 2015
1 parent 9edec4e commit 836f2e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions llvm/include/llvm/Object/ELF.h
Expand Up @@ -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();
Expand Down
Binary file not shown.
6 changes: 6 additions & 0 deletions llvm/test/Object/corrupt.test
Expand Up @@ -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

0 comments on commit 836f2e8

Please sign in to comment.