[Object/ELF] - Do not allow overflow when checking section size/offset.

Overflow was the reason of incorrect passing the check,
patch fixes the case.

Differentail revision: https://reviews.llvm.org/D25514

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285284 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
George Rimar 2016-10-27 11:44:56 +00:00
parent 2bbde38ea6
commit 464f0d7886
3 changed files with 6 additions and 1 deletions

View File

@ -229,7 +229,8 @@ ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
if (Size % sizeof(T))
return object_error::parse_failed;
if (Offset + Size > Buf.size())
if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
Offset + Size > Buf.size())
return object_error::parse_failed;
const T *Start = reinterpret_cast<const T *>(base() + Offset);

Binary file not shown.

View File

@ -72,3 +72,7 @@ INVALID-RELOC-SH-OFFSET: Invalid data was encountered while parsing the file
RUN: not llvm-readobj -t %p/Inputs/invalid-sections-address-alignment.x86-64 2>&1 | \
RUN: FileCheck --check-prefix=INVALID-SEC-ADDRESS-ALIGNMENT %s
INVALID-SEC-ADDRESS-ALIGNMENT: Invalid data was encountered while parsing the file
RUN: not llvm-readobj -t %p/Inputs/invalid-section-size2.elf 2>&1 | \
RUN: FileCheck --check-prefix=INVALID-SECTION-SIZE2 %s
INVALID-SECTION-SIZE2: Invalid data was encountered while parsing the file.