forked from OSchip/llvm-project
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 llvm-svn: 354145
This commit is contained in:
parent
8a2b543a13
commit
42a9da7b35
lldb/source/Plugins/ScriptInterpreter/Python
|
@ -2781,6 +2781,11 @@ bool ScriptInterpreterPython::LoadScriptingModule(
|
|||
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, "'", "\\'");
|
||||
|
|
Loading…
Reference in New Issue