[PATCH] D34554: [ELF] FIx use-after-return of archive path
Igor Kudrin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 15 19:29:00 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD325313: [ELF] Fix use after free in case of using --whole-archive. (authored by ikudrin, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D34554?vs=134415&id=134550#toc
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D34554
Files:
ELF/Driver.cpp
ELF/InputFiles.h
ELF/InputSection.cpp
test/ELF/whole-archive-name.s
Index: test/ELF/whole-archive-name.s
===================================================================
--- test/ELF/whole-archive-name.s
+++ test/ELF/whole-archive-name.s
@@ -0,0 +1,15 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+// RUN: mkdir -p %t.dir
+// RUN: rm -f %t.dir/liba.a
+// RUN: llvm-ar rcs %t.dir/liba.a %t.o
+// RUN: ld.lld -L%t.dir --whole-archive -la -o %t -Map=- | FileCheck %s
+
+.globl _start
+_start:
+ nop
+
+// There was a use after free of an archive name.
+// Valgrind/asan would detect it.
+// CHECK: liba.a(whole-archive-name.s.tmp.o):(.text)
+// CHECK-NEXT: _start
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -277,7 +277,7 @@
std::string Archive;
if (!File->ArchiveName.empty())
- Archive = (" in archive " + File->ArchiveName).str();
+ Archive = " in archive " + File->ArchiveName;
// Find a symbol that encloses a given location.
for (Symbol *B : File->getSymbols())
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -984,7 +984,7 @@
if (isa<ArchiveFile>(File))
return File->getName();
if (!File->ArchiveName.empty())
- return File->ArchiveName;
+ return StringRef(File->ArchiveName);
return None;
}
Index: ELF/InputFiles.h
===================================================================
--- ELF/InputFiles.h
+++ ELF/InputFiles.h
@@ -98,7 +98,7 @@
// Filename of .a which contained this file. If this file was
// not in an archive file, it is the empty string. We use this
// string for creating error messages.
- StringRef ArchiveName;
+ std::string ArchiveName;
// If this is an architecture-specific file, the following members
// have ELF type (i.e. ELF{32,64}{LE,BE}) and target machine type.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34554.134550.patch
Type: text/x-patch
Size: 1944 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180216/41ebbb28/attachment.bin>
More information about the llvm-commits
mailing list