diff options
Diffstat (limited to 'llvm/lib/Object/ELF.cpp')
-rw-r--r-- | llvm/lib/Object/ELF.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp index f17a6da..d1bf469 100644 --- a/llvm/lib/Object/ELF.cpp +++ b/llvm/lib/Object/ELF.cpp @@ -580,7 +580,18 @@ Expected<const uint8_t *> ELFFile<ELFT>::toMappedAddr(uint64_t VAddr) const { if (Delta >= Phdr.p_filesz) return createError("virtual address is not in any segment: 0x" + Twine::utohexstr(VAddr)); - return base() + Phdr.p_offset + Delta; + + uint64_t Offset = Phdr.p_offset + Delta; + if (Offset >= getBufSize()) + return createError("can't map virtual address 0x" + + Twine::utohexstr(VAddr) + " to the segment with index " + + Twine(&Phdr - (*ProgramHeadersOrError).data() + 1) + + ": the segment ends at 0x" + + Twine::utohexstr(Phdr.p_offset + Phdr.p_filesz) + + ", which is greater than the file size (0x" + + Twine::utohexstr(getBufSize()) + ")"); + + return base() + Offset; } template class llvm::object::ELFFile<ELF32LE>; |