[PATCH] D14451: [ELF2] - Fixed crash for case when section sh_entsize is set to zero for SHF_MERGE type of sections.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 6 09:01:21 PST 2015


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

Fixed crash for incorrect elf input, bfd does not crash btw.

http://reviews.llvm.org/D14451

Files:
  ELF/InputFiles.cpp
  test/elf2/Inputs/invalid-shentsize-zero.elf
  test/elf2/invalid-elf.test

Index: test/elf2/invalid-elf.test
===================================================================
--- test/elf2/invalid-elf.test
+++ test/elf2/invalid-elf.test
@@ -23,4 +23,8 @@
 # RUN: not ld.lld2 %p/Inputs/invalid-shstrndx.so -o %t2 2>&1 | \
 # RUN:   FileCheck --check-prefix=INVALID-SECTION-INDEX %s
 
+# RUN: not ld.lld2 %p/Inputs/invalid-shentsize-zero.elf -o %t2 2>&1 | \
+# RUN:   FileCheck --check-prefix=INVALID-SHENTSIZE-ZERO %s
+# INVALID-SHENTSIZE-ZERO: SHF_MERGE section size must be a multiple of sh_entsize
+
 .long foo
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -143,7 +143,7 @@
   if (Flags & SHF_WRITE)
     error("Writable SHF_MERGE sections are not supported");
   uintX_t EntSize = Sec.sh_entsize;
-  if (Sec.sh_size % EntSize)
+  if (!EntSize || Sec.sh_size % EntSize)
     error("SHF_MERGE section size must be a multiple of sh_entsize");
 
   // Don't try to merge if the aligment is larger than the sh_entsize.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14451.39546.patch
Type: text/x-patch
Size: 1041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151106/df21d9dc/attachment.bin>


More information about the llvm-commits mailing list