[lld] r325313 - [ELF] Fix use after free in case of using --whole-archive.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 15 19:26:53 PST 2018


Author: ikudrin
Date: Thu Feb 15 19:26:53 2018
New Revision: 325313

URL: http://llvm.org/viewvc/llvm-project?rev=325313&view=rev
Log:
[ELF] Fix use after free in case of using --whole-archive.

Differential Revision: https://reviews.llvm.org/D34554

Added:
    lld/trunk/test/ELF/whole-archive-name.s
Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/InputFiles.h
    lld/trunk/ELF/InputSection.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=325313&r1=325312&r2=325313&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Feb 15 19:26:53 2018
@@ -984,7 +984,7 @@ static Optional<StringRef> getArchiveNam
   if (isa<ArchiveFile>(File))
     return File->getName();
   if (!File->ArchiveName.empty())
-    return File->ArchiveName;
+    return StringRef(File->ArchiveName);
   return None;
 }
 

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=325313&r1=325312&r2=325313&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Thu Feb 15 19:26:53 2018
@@ -98,7 +98,7 @@ public:
   // 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.

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=325313&r1=325312&r2=325313&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Feb 15 19:26:53 2018
@@ -277,7 +277,7 @@ std::string InputSectionBase::getObjMsg(
 
   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())

Added: lld/trunk/test/ELF/whole-archive-name.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/whole-archive-name.s?rev=325313&view=auto
==============================================================================
--- lld/trunk/test/ELF/whole-archive-name.s (added)
+++ lld/trunk/test/ELF/whole-archive-name.s Thu Feb 15 19:26:53 2018
@@ -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




More information about the llvm-commits mailing list