[llvm] r268924 - [dsymutil] Prevent use-after-free

Frederic Riss via llvm-commits llvm-commits at lists.llvm.org
Mon May 9 07:44:15 PDT 2016


Author: friss
Date: Mon May  9 09:44:14 2016
New Revision: 268924

URL: http://llvm.org/viewvc/llvm-project?rev=268924&view=rev
Log:
[dsymutil] Prevent use-after-free

The BinaryHolder would query the archive member MemoryBuffer name
to check if the current open archive also contains the next requested
objectfile. This comparison was using a StringRef to a temporary
buffer. It only happened with fat archives. This commit adds long-lived
storage along with the MemoryBuffers for the fat archive filename.

The added test would fail during an ASAN build without the fix.

Added:
    llvm/trunk/test/tools/dsymutil/Inputs/basic-with-libfat-test.macho.x86_64   (with props)
    llvm/trunk/test/tools/dsymutil/X86/basic-with-libfat-test.test
Modified:
    llvm/trunk/tools/dsymutil/BinaryHolder.cpp
    llvm/trunk/tools/dsymutil/BinaryHolder.h

Added: llvm/trunk/test/tools/dsymutil/Inputs/basic-with-libfat-test.macho.x86_64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/basic-with-libfat-test.macho.x86_64?rev=268924&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/basic-with-libfat-test.macho.x86_64 (added) and llvm/trunk/test/tools/dsymutil/Inputs/basic-with-libfat-test.macho.x86_64 Mon May  9 09:44:14 2016 differ

Propchange: llvm/trunk/test/tools/dsymutil/Inputs/basic-with-libfat-test.macho.x86_64
------------------------------------------------------------------------------
    svn:executable = *

Added: llvm/trunk/test/tools/dsymutil/X86/basic-with-libfat-test.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/basic-with-libfat-test.test?rev=268924&view=auto
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/basic-with-libfat-test.test (added)
+++ llvm/trunk/test/tools/dsymutil/X86/basic-with-libfat-test.test Mon May  9 09:44:14 2016
@@ -0,0 +1,10 @@
+RUN: llvm-dsymutil -f -o - -oso-prepend-path=%p/.. %p/../Inputs/basic-with-libfat-test.macho.x86_64 | llvm-dwarfdump - | FileCheck %s 
+
+The test binary was created by force-linking the libfat-test.a fat archive
+with the basic linking test archive, like so:
+$ clang -all_load libfat-test.a libbasic.a basic1.macho.x86_64.o -Wl,-dead_strip -u _x86_64_var
+
+CHECK: DW_AT_name{{.*}}"x86_64_var"
+CHECK: DW_AT_name{{.*}}"basic2.c"
+CHECK: DW_AT_name{{.*}}"basic3.c"
+CHECK: DW_AT_name{{.*}}"basic1.c"

Modified: llvm/trunk/tools/dsymutil/BinaryHolder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/BinaryHolder.cpp?rev=268924&r1=268923&r2=268924&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/BinaryHolder.cpp (original)
+++ llvm/trunk/tools/dsymutil/BinaryHolder.cpp Mon May  9 09:44:14 2016
@@ -79,7 +79,8 @@ BinaryHolder::GetMemoryBuffersForFile(St
   }
 
   CurrentFatBinary = std::move(*ErrOrFat);
-  return getMachOFatMemoryBuffers(Filename, *CurrentMemoryBuffer,
+  CurrentFatBinaryName = Filename;
+  return getMachOFatMemoryBuffers(CurrentFatBinaryName, *CurrentMemoryBuffer,
                                   *CurrentFatBinary);
 }
 
@@ -149,8 +150,9 @@ BinaryHolder::MapArchiveAndGetMemberBuff
     ArchiveBuffers.push_back(CurrentMemoryBuffer->getMemBufferRef());
   } else {
     CurrentFatBinary = std::move(*ErrOrFat);
+    CurrentFatBinaryName = ArchiveFilename;
     ArchiveBuffers = getMachOFatMemoryBuffers(
-        ArchiveFilename, *CurrentMemoryBuffer, *CurrentFatBinary);
+        CurrentFatBinaryName, *CurrentMemoryBuffer, *CurrentFatBinary);
   }
 
   for (auto MemRef : ArchiveBuffers) {

Modified: llvm/trunk/tools/dsymutil/BinaryHolder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/BinaryHolder.h?rev=268924&r1=268923&r2=268924&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/BinaryHolder.h (original)
+++ llvm/trunk/tools/dsymutil/BinaryHolder.h Mon May  9 09:44:14 2016
@@ -42,6 +42,7 @@ class BinaryHolder {
   std::unique_ptr<MemoryBuffer> CurrentMemoryBuffer;
   std::vector<std::unique_ptr<object::ObjectFile>> CurrentObjectFiles;
   std::unique_ptr<object::MachOUniversalBinary> CurrentFatBinary;
+  std::string CurrentFatBinaryName;
   bool Verbose;
 
   /// Get the MemoryBufferRefs for the file specification in \p




More information about the llvm-commits mailing list