[PATCH] D91012: [llvm] [Support] Fix segv if argv0 is null in getMainExecutable()

Michał Górny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 7 13:08:32 PST 2020


mgorny created this revision.
mgorny added reviewers: labath, emaste, krytarowski, espindola.
Herald added subscribers: dexonsmith, hiraditya, arichardson.
Herald added a project: LLVM.
mgorny requested review of this revision.

When LLDB Python bindings are used and stack backtraces are enabled
for logging, getMainExecutable() is called with argv0 being null.
This caused the fallback function getprogpath() (used on FreeBSD, NetBSD
and Linux) to segfault.  Make it handle null executable name gracefully.


https://reviews.llvm.org/D91012

Files:
  lldb/test/API/commands/log/basic/TestLogging.py
  llvm/lib/Support/Unix/Path.inc


Index: llvm/lib/Support/Unix/Path.inc
===================================================================
--- llvm/lib/Support/Unix/Path.inc
+++ llvm/lib/Support/Unix/Path.inc
@@ -147,6 +147,9 @@
 static char *
 getprogpath(char ret[PATH_MAX], const char *bin)
 {
+  if (bin == nullptr)
+    return nullptr;
+
   /* First approach: absolute path. */
   if (bin[0] == '/') {
     if (test_dir(ret, "/", bin) == 0)
Index: lldb/test/API/commands/log/basic/TestLogging.py
===================================================================
--- lldb/test/API/commands/log/basic/TestLogging.py
+++ lldb/test/API/commands/log/basic/TestLogging.py
@@ -93,8 +93,6 @@
 
     # Enable all log options and check that nothing crashes.
     @skipIfWindows
-    # TODO: figure out why it segfaults
-    @skipIfFreeBSD
     def test_all_log_options(self):
         if (os.path.exists(self.log_file)):
             os.remove(self.log_file)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91012.303666.patch
Type: text/x-patch
Size: 923 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201107/271755e2/attachment.bin>


More information about the llvm-commits mailing list