[PATCH] D38512: Added phdr upper bound checks to ElfObject
Parker Thompson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 3 12:52:08 PDT 2017
mothran created this revision.
Ensure the program_headers call will fail correctly if the program
headers are larger than the underlying buffer
https://reviews.llvm.org/D38512
Files:
include/llvm/Object/ELF.h
Index: include/llvm/Object/ELF.h
===================================================================
--- include/llvm/Object/ELF.h
+++ include/llvm/Object/ELF.h
@@ -144,6 +144,8 @@
Expected<Elf_Phdr_Range> program_headers() const {
if (getHeader()->e_phnum && getHeader()->e_phentsize != sizeof(Elf_Phdr))
return createError("invalid e_phentsize");
+ if (getHeader()->e_phoff + (getHeader()->e_phnum * getHeader()->e_phentsize) > getBufSize())
+ return createError("program headers longer than binary");
auto *Begin =
reinterpret_cast<const Elf_Phdr *>(base() + getHeader()->e_phoff);
return makeArrayRef(Begin, Begin + getHeader()->e_phnum);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38512.117564.patch
Type: text/x-patch
Size: 685 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171003/45e20b71/attachment.bin>
More information about the llvm-commits
mailing list