[lld] r283097 - [ELF] - Do not crash on invalid section alignment.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 3 03:04:38 PDT 2016


Author: grimar
Date: Mon Oct  3 05:04:38 2016
New Revision: 283097

URL: http://llvm.org/viewvc/llvm-project?rev=283097&view=rev
Log:
[ELF] - Do not crash on invalid section alignment.

Case was revealed by id_000010,sig_08,src_000000,op_havoc,rep_4 from PR30540.

Out implementation uses uint32 for storing section alignment value,
what seems reasonable, though if value exceeds 32 bits bounds we have
truncation and final value of 0.

Patch fixes the issue.

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

Added:
    lld/trunk/test/ELF/invalid/section-alignment.test
Modified:
    lld/trunk/ELF/InputSection.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=283097&r1=283096&r2=283097&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Mon Oct  3 05:04:38 2016
@@ -45,6 +45,8 @@ InputSectionBase<ELFT>::InputSectionBase
       Header(Hdr), File(File), Repl(this) {
   // The ELF spec states that a value of 0 means the section has
   // no alignment constraits.
+  if (Header->sh_addralign > UINT32_MAX)
+    fatal(getFilename(File) + ": section sh_addralign is too large");
   Alignment = std::max<uintX_t>(Header->sh_addralign, 1);
 }
 

Added: lld/trunk/test/ELF/invalid/section-alignment.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/section-alignment.test?rev=283097&view=auto
==============================================================================
--- lld/trunk/test/ELF/invalid/section-alignment.test (added)
+++ lld/trunk/test/ELF/invalid/section-alignment.test Mon Oct  3 05:04:38 2016
@@ -0,0 +1,19 @@
+# RUN: yaml2obj %s -o %t
+# RUN: not ld.lld %t -o %tout 2>&1 | FileCheck %s
+
+## In current lld implementation, we do not accept sh_addralign
+## larger than UINT32_MAX.
+!ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x1000000000000001
+    Content:         "00000000"
+
+# CHECK: section sh_addralign is too large




More information about the llvm-commits mailing list