Index: llvm/trunk/include/llvm/Object/ELF.h =================================================================== --- llvm/trunk/include/llvm/Object/ELF.h +++ llvm/trunk/include/llvm/Object/ELF.h @@ -399,9 +399,11 @@ if (Index >= getNumSections()) return object_error::invalid_section_index; - return reinterpret_cast( - reinterpret_cast(SectionHeaderTable) + - (Index * Header->e_shentsize)); + const uint8_t *Addr = reinterpret_cast(SectionHeaderTable) + + (Index * Header->e_shentsize); + if (Addr >= base() + getBufSize()) + return object_error::invalid_section_index; + return reinterpret_cast(Addr); } template Index: llvm/trunk/test/Object/invalid.test =================================================================== --- llvm/trunk/test/Object/invalid.test +++ llvm/trunk/test/Object/invalid.test @@ -41,7 +41,7 @@ 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