[lld] r284227 - [ELF] - Do not crash when object has multiple SHT_MIPS_OPTIONS

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 14 04:10:36 PDT 2016


Author: grimar
Date: Fri Oct 14 06:10:36 2016
New Revision: 284227

URL: http://llvm.org/viewvc/llvm-project?rev=284227&view=rev
Log:
[ELF] - Do not crash when object has multiple SHT_MIPS_OPTIONS

Issue was revealed by AFl and I was able to generate such object using yaml2obj.

When object has more than one SHT_MIPS_OPTIONS, 
each except the last one is destroyed after placing into Sections array.
Sections array contains dead pointers finally. LLD may crash then.

Differential revision: https://reviews.llvm.org/D25555

Added:
    lld/trunk/test/ELF/invalid/mips-multiple-options.test
Modified:
    lld/trunk/ELF/InputFiles.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=284227&r1=284226&r2=284227&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Oct 14 06:10:36 2016
@@ -324,6 +324,9 @@ elf::ObjectFile<ELFT>::createInputSectio
     MipsReginfo.reset(new MipsReginfoInputSection<ELFT>(this, &Sec, Name));
     return MipsReginfo.get();
   case SHT_MIPS_OPTIONS:
+    if (MipsOptions)
+      fatal(getFilename(this) +
+            ": multiple SHT_MIPS_OPTIONS sections are not allowed");
     MipsOptions.reset(new MipsOptionsInputSection<ELFT>(this, &Sec, Name));
     return MipsOptions.get();
   case SHT_MIPS_ABIFLAGS:

Added: lld/trunk/test/ELF/invalid/mips-multiple-options.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/mips-multiple-options.test?rev=284227&view=auto
==============================================================================
--- lld/trunk/test/ELF/invalid/mips-multiple-options.test (added)
+++ lld/trunk/test/ELF/invalid/mips-multiple-options.test Fri Oct 14 06:10:36 2016
@@ -0,0 +1,25 @@
+# RUN: yaml2obj %s -o %t
+# RUN: not ld.lld %t -o %tout 2>&1 | FileCheck %s
+
+--- !ELF
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+  - Name:          .o1
+    Type:          SHT_MIPS_OPTIONS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  16
+    Content:       "010000000000000000000000"
+
+  - Name:          .o2
+    Type:          SHT_MIPS_OPTIONS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  16
+    Content:       "010000000000000000000000"
+
+# CHECK: multiple SHT_MIPS_OPTIONS sections are not allowed




More information about the llvm-commits mailing list