aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/ELF.cpp
diff options
context:
space:
mode:
authorGeorgii Rymar <grimar@accesssoftek.com>2020-03-24 17:26:52 +0300
committerGeorgii Rymar <grimar@accesssoftek.com>2020-03-27 13:18:08 +0300
commit30c1f9a5584eaf8d7571cc3e18edf1691a88ae7b (patch)
tree4da011be53361470a888f5457e1c0882c54ba10a /llvm/lib/Object/ELF.cpp
parentc16c07d4b9adb43065f875176701f9a1f6e67a5e (diff)
downloadllvm-30c1f9a5584eaf8d7571cc3e18edf1691a88ae7b.zip
llvm-30c1f9a5584eaf8d7571cc3e18edf1691a88ae7b.tar.gz
llvm-30c1f9a5584eaf8d7571cc3e18edf1691a88ae7b.tar.bz2
[llvm-readobj] - Fix a crash when DT_STRTAB is broken.
We might have a crash scenario when we have an invalid DT_STRTAB value that is larger than the file size. I've added a test case to demonstrate. Differential revision: https://reviews.llvm.org/D76706
Diffstat (limited to 'llvm/lib/Object/ELF.cpp')
-rw-r--r--llvm/lib/Object/ELF.cpp13
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>;