[PATCH] D25368: [Object/ELF] - Do not crash on invalid Header->e_shoff value.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 7 08:43:56 PDT 2016


grimar updated this revision to Diff 73937.
grimar added a comment.

- As suggested by Rafael, check only alignment of Header->e_shoff.


https://reviews.llvm.org/D25368

Files:
  include/llvm/Object/ELF.h
  test/Object/Inputs/invalid-sections-address-alignment.x86-64
  test/Object/invalid.test


Index: test/Object/invalid.test
===================================================================
--- test/Object/invalid.test
+++ test/Object/invalid.test
@@ -64,3 +64,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 address alignment of section headers
Index: include/llvm/Object/ELF.h
===================================================================
--- include/llvm/Object/ELF.h
+++ include/llvm/Object/ELF.h
@@ -367,6 +367,8 @@
   if (Header->e_shentsize != sizeof(Elf_Shdr))
     report_fatal_error(
         "Invalid section header entry size (e_shentsize) in ELF header");
+  if (Header->e_shoff & (AlignOf<typename ELFT::uint>::Alignment - 1))
+    report_fatal_error("Invalid address alignment of section headers");
   return reinterpret_cast<const Elf_Shdr *>(base() + Header->e_shoff);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25368.73937.patch
Type: text/x-patch
Size: 1201 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161007/71c3ca80/attachment-0001.bin>


More information about the llvm-commits mailing list