[PATCH] D25081: [Object/ELF] - Do not crash on invalid section index.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 17 02:39:32 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284369: [Object/ELF] - Do not crash on invalid section index. (authored by grimar).
Changed prior to commit:
https://reviews.llvm.org/D25081?vs=73010&id=74821#toc
Repository:
rL LLVM
https://reviews.llvm.org/D25081
Files:
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/test/Object/Inputs/invalid-section-index2.elf
llvm/trunk/test/Object/invalid.test
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<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>
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25081.74821.patch
Type: text/x-patch
Size: 1408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161017/fb1d2446/attachment.bin>
More information about the llvm-commits
mailing list