From 96d9043a78bebbb18881632cd3bcb2f61a84d17a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 20 Jul 2015 14:45:03 +0000 Subject: [PATCH] Report errors an invalid virtual addresses. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242676 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/ELF.h | 8 ++++++-- .../corrupt-invalid-virtual-addr.elf.x86-64 | Bin 0 -> 1720 bytes test/Object/corrupt.test | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100755 test/Object/Inputs/corrupt-invalid-virtual-addr.elf.x86-64 diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 085595ed621..509355b105d 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -738,9 +738,13 @@ template void ELFFile::scanDynamicTable() { const Elf_Phdr **I = std::upper_bound( LoadSegments.begin(), LoadSegments.end(), VAddr, compareAddr); 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(); diff --git a/test/Object/Inputs/corrupt-invalid-virtual-addr.elf.x86-64 b/test/Object/Inputs/corrupt-invalid-virtual-addr.elf.x86-64 new file mode 100755 index 0000000000000000000000000000000000000000..58d995933ecadffe435c6044763bc67adaa41d63 GIT binary patch literal 1720 zcmcIky-piJ5FY=KKuqDF6dk3zZdnr}@U6z_WP`avL)7*LdX*_Y!=7_Oi<06>YA&643?ME1n(i zi+C909z}*Xfvwy9YJMuKhJ5Sk)Dw@4Uo%7u*x2-bc7MN!x1=BN-Qg!W>3{94H(aA} zOGtmbYMOs8$Gexx3zE+#(p;1eyh{=PYz{BX&F<&J*9Y%+=I6~N;V==W=@i!)MR76^ z7xk0SokV92*W5f02k~h?^6pVjTsMfjvsutPJr);tRg?s69T7*p*?d+idcwQg3*7=W z!g^xe5WiRm`0?iaKd_#bmCM%ScdHvB>&mv7?ZGi{OFz^k^#9r}0rQF!1-%NVNz>J^R3r0`+ArAOE2`vFHEl(NC~P z-WdOB&XJG*QT;_ny)^Q|^ym{fBk#}r?;CH+Qh06`+DI8c$fxCv(!6_i=?5d*SyIP& F{cnshZSw#C literal 0 HcmV?d00001 diff --git a/test/Object/corrupt.test b/test/Object/corrupt.test index 7c4b1c775ec..9b3daf7b4cf 100644 --- a/test/Object/corrupt.test +++ b/test/Object/corrupt.test @@ -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