[llvm] r242676 - Report errors an invalid virtual addresses.
Rafael Espindola
rafael.espindola at gmail.com
Mon Jul 20 07:45:03 PDT 2015
Author: rafael
Date: Mon Jul 20 09:45:03 2015
New Revision: 242676
URL: http://llvm.org/viewvc/llvm-project?rev=242676&view=rev
Log:
Report errors an invalid virtual addresses.
Added:
llvm/trunk/test/Object/Inputs/corrupt-invalid-virtual-addr.elf.x86-64 (with props)
Modified:
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/test/Object/corrupt.test
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=242676&r1=242675&r2=242676&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Mon Jul 20 09:45:03 2015
@@ -738,9 +738,13 @@ template <class ELFT> void ELFFile<ELFT>
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();
Added: llvm/trunk/test/Object/Inputs/corrupt-invalid-virtual-addr.elf.x86-64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/corrupt-invalid-virtual-addr.elf.x86-64?rev=242676&view=auto
==============================================================================
Binary files llvm/trunk/test/Object/Inputs/corrupt-invalid-virtual-addr.elf.x86-64 (added) and llvm/trunk/test/Object/Inputs/corrupt-invalid-virtual-addr.elf.x86-64 Mon Jul 20 09:45:03 2015 differ
Propchange: llvm/trunk/test/Object/Inputs/corrupt-invalid-virtual-addr.elf.x86-64
------------------------------------------------------------------------------
svn:executable = *
Modified: llvm/trunk/test/Object/corrupt.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/corrupt.test?rev=242676&r1=242675&r2=242676&view=diff
==============================================================================
--- llvm/trunk/test/Object/corrupt.test (original)
+++ llvm/trunk/test/Object/corrupt.test Mon Jul 20 09:45:03 2015
@@ -37,3 +37,9 @@ RUN: %p/Inputs/corrupt-invalid-phentsi
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
More information about the llvm-commits
mailing list