llvm.org GIT mirror llvm / 464f0d7
[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 George Rimar 3 years ago
3 changed file(s) with 6 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
228228
229229 if (Size % sizeof(T))
230230 return object_error::parse_failed;
231 if (Offset + Size > Buf.size())
231 if ((std::numeric_limits::max() - Offset < Size) ||
232 Offset + Size > Buf.size())
232233 return object_error::parse_failed;
233234
234235 const T *Start = reinterpret_cast(base() + Offset);
7171 RUN: not llvm-readobj -t %p/Inputs/invalid-sections-address-alignment.x86-64 2>&1 | \
7272 RUN: FileCheck --check-prefix=INVALID-SEC-ADDRESS-ALIGNMENT %s
7373 INVALID-SEC-ADDRESS-ALIGNMENT: Invalid data was encountered while parsing the file
74
75 RUN: not llvm-readobj -t %p/Inputs/invalid-section-size2.elf 2>&1 | \
76 RUN: FileCheck --check-prefix=INVALID-SECTION-SIZE2 %s
77 INVALID-SECTION-SIZE2: Invalid data was encountered while parsing the file.