If object has wrong (large) string table index and
also incorrect large value for amount of sections in total,
then section index passes the check:
if (Index >= getNumSections())
return object_error::invalid_section_index;
But result pointer then is far after end of file data, what
result in a crash.
Differential revision: https://reviews.llvm.org/D25081
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284369
91177308-0d34-0410-b5e6-
96231b3b80d8
if (Index >= getNumSections())
return object_error::invalid_section_index;
- return reinterpret_cast<const Elf_Shdr *>(
- reinterpret_cast<const char *>(SectionHeaderTable) +
- (Index * Header->e_shentsize));
+ const uint8_t *Addr = reinterpret_cast<const uint8_t *>(SectionHeaderTable) +
+ (Index * Header->e_shentsize);
+ if (Addr >= base() + getBufSize())
+ return object_error::invalid_section_index;
+ return reinterpret_cast<const Elf_Shdr *>(Addr);
}
template <class ELFT>
INVALID-DYNSYM-SIZE: Invalid entity size
RUN: not llvm-readobj -t %p/Inputs/invalid-section-index.elf 2>&1 | FileCheck --check-prefix=INVALID-SECTION-INDEX %s
-
+RUN: not llvm-readobj -t %p/Inputs/invalid-section-index2.elf 2>&1 | FileCheck --check-prefix=INVALID-SECTION-INDEX %s
INVALID-SECTION-INDEX: Invalid section index
RUN: not llvm-readobj -s %p/Inputs/invalid-section-size.elf 2>&1 | FileCheck --check-prefix=INVALID-SECTION-SIZE %s