[PATCH] D137959: [dsymutil] Fix crash in the Reproducer/FileCollector when TMPDIR is empty

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 14 09:35:18 PST 2022


JDevlieghere created this revision.
JDevlieghere added a reviewer: arphaman.
Herald added a subscriber: hiraditya.
Herald added a project: All.
JDevlieghere requested review of this revision.
Herald added a project: LLVM.

Fix a crash in dsymutil caused by the Reproducer/FileCollector when TMPDIR is empty.


https://reviews.llvm.org/D137959

Files:
  llvm/lib/Support/FileCollector.cpp
  llvm/test/tools/dsymutil/X86/reproducer.test
  llvm/tools/dsymutil/Reproducer.cpp


Index: llvm/tools/dsymutil/Reproducer.cpp
===================================================================
--- llvm/tools/dsymutil/Reproducer.cpp
+++ llvm/tools/dsymutil/Reproducer.cpp
@@ -20,6 +20,7 @@
   } else {
     EC = sys::fs::createUniqueDirectory("dsymutil", Root);
   }
+  sys::fs::make_absolute(Root);
   return EC ? "" : std::string(Root);
 }
 
Index: llvm/test/tools/dsymutil/X86/reproducer.test
===================================================================
--- llvm/test/tools/dsymutil/X86/reproducer.test
+++ llvm/test/tools/dsymutil/X86/reproducer.test
@@ -13,6 +13,9 @@
 # Verify all the files are present.
 RUN: dsymutil -f -o - -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 | llvm-dwarfdump -a - | FileCheck %s
 
+# Make sure we don't crash with an empty TMPDIR.
+RUN: env TMPDIR="" dsymutil -o -f %t.generate -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 2>&1
+
 # Create a reproducer.
 RUN: env DSYMUTIL_REPRODUCER_PATH=%t.repro dsymutil -gen-reproducer -f -o %t.generate -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 2>&1 | FileCheck %s --check-prefixes=REPRODUCER
 RUN: llvm-dwarfdump -a %t.generate | FileCheck %s
Index: llvm/lib/Support/FileCollector.cpp
===================================================================
--- llvm/lib/Support/FileCollector.cpp
+++ llvm/lib/Support/FileCollector.cpp
@@ -50,7 +50,9 @@
 }
 
 FileCollector::FileCollector(std::string Root, std::string OverlayRoot)
-    : Root(std::move(Root)), OverlayRoot(std::move(OverlayRoot)) {
+    : Root(Root), OverlayRoot(OverlayRoot) {
+  assert(sys::path::is_absolute(Root) && "Root not absolute");
+  assert(sys::path::is_absolute(OverlayRoot) && "OverlayRoot not absolute");
 }
 
 void FileCollector::PathCanonicalizer::updateWithRealPath(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137959.475178.patch
Type: text/x-patch
Size: 1764 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221114/78b5af9b/attachment.bin>


More information about the llvm-commits mailing list