[Lldb-commits] [lldb] r354145 - Fix potential UB when target_file directory is null

Stefan Granitz via lldb-commits lldb-commits at lists.llvm.org
Fri Feb 15 08:42:29 PST 2019


Author: stefan.graenitz
Date: Fri Feb 15 08:42:29 2019
New Revision: 354145

URL: http://llvm.org/viewvc/llvm-project?rev=354145&view=rev
Log:
Fix potential UB when target_file directory is null

Summary: As seen in a crash report, the C-string returned for the directory component of `target_file` can null. It should not be assigned to `std::string` directly as this is undefined behavior.

Reviewers: jingham

Reviewed By: jingham

Subscribers: jdoerfert, lldb-commits, #lldb

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

Modified:
    lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp?rev=354145&r1=354144&r2=354145&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp Fri Feb 15 08:42:29 2019
@@ -2781,6 +2781,11 @@ bool ScriptInterpreterPython::LoadScript
       basename = pathname; // not a filename, probably a package of some sort,
                            // let it go through
     } else if (is_directory(st) || is_regular_file(st)) {
+      if (target_file.GetDirectory().IsEmpty()) {
+        error.SetErrorString("invalid directory name");
+        return false;
+      }
+
       std::string directory = target_file.GetDirectory().GetCString();
       replace_all(directory, "\\", "\\\\");
       replace_all(directory, "'", "\\'");




More information about the lldb-commits mailing list