[PATCH] D51743: [ELF] Check if LinkSec is nullptr when initializing SHF_LINK_ORDER sections
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 6 11:19:51 PDT 2018
MaskRay created this revision.
MaskRay added a reviewer: ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D51743
Files:
ELF/InputFiles.cpp
test/ELF/invalid/linkorder-invalid-sec2.test
Index: test/ELF/invalid/linkorder-invalid-sec2.test
===================================================================
--- /dev/null
+++ test/ELF/invalid/linkorder-invalid-sec2.test
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: yaml2obj %s -o %t.o
+# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
+# CHECK: invalid sh_link index: 0
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .linkorder
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_LINK_ORDER ]
+ Link: 0
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -478,11 +478,13 @@
// .ARM.exidx sections have a reverse dependency on the InputSection they
// have a SHF_LINK_ORDER dependency, this is identified by the sh_link.
if (Sec.sh_flags & SHF_LINK_ORDER) {
- if (Sec.sh_link >= this->Sections.size())
+ InputSectionBase *LinkSec = Sec.sh_link < this->Sections.size()
+ ? this->Sections[Sec.sh_link]
+ : nullptr;
+ if (!LinkSec)
fatal(toString(this) +
": invalid sh_link index: " + Twine(Sec.sh_link));
- InputSectionBase *LinkSec = this->Sections[Sec.sh_link];
InputSection *IS = cast<InputSection>(this->Sections[I]);
LinkSec->DependentSections.push_back(IS);
if (!isa<InputSection>(LinkSec))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51743.164250.patch
Type: text/x-patch
Size: 1582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180906/374f180b/attachment.bin>
More information about the llvm-commits
mailing list