[PATCH] D25462: [Object/ELF] - Check Header->e_shoff value earlier and do not crash.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 17 07:37:33 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL284387: [Object/ELF] - Check Header->e_shoff value earlier and do not crash. (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D25462?vs=74205&id=74844#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25462

Files:
  llvm/trunk/include/llvm/Object/ELF.h
  llvm/trunk/test/Object/Inputs/invalid-sections-address-alignment.x86-64
  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
@@ -334,6 +334,12 @@
     return;
   }
 
+  if (SectionTableOffset & (AlignOf<Elf_Shdr>::Alignment - 1)) {
+    // Invalid address alignment of section headers
+    EC = object_error::parse_failed;
+    return;
+  }
+
   // The getNumSections() call below depends on SectionHeaderTable being set.
   SectionHeaderTable =
     reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset);
Index: llvm/trunk/test/Object/invalid.test
===================================================================
--- llvm/trunk/test/Object/invalid.test
+++ llvm/trunk/test/Object/invalid.test
@@ -67,3 +67,7 @@
 RUN: not llvm-readobj -r %p/Inputs/invalid-relocation-sec-sh_offset.elf-x86-64 2>&1 | \
 RUN:   FileCheck --check-prefix=INVALID-RELOC-SH-OFFSET %s
 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25462.74844.patch
Type: text/x-patch
Size: 1260 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161017/38bb4025/attachment.bin>


More information about the llvm-commits mailing list