diff options
author | Jason Molenda <jmolenda@apple.com> | 2016-02-19 00:05:17 +0000 |
---|---|---|
committer | Jason Molenda <jmolenda@apple.com> | 2016-02-19 00:05:17 +0000 |
commit | 878ae0188919c0499ce2623cf50d8a0edc61d558 (patch) | |
tree | ac2bfc2c35afbd7dd6ca8aa488c0eb3039cb3709 /lldb/source/Interpreter/CommandInterpreter.cpp | |
parent | 7b71c0ba6cb3cab0bdbcc17cf944e779d2ff66e8 (diff) | |
download | bcm5719-llvm-878ae0188919c0499ce2623cf50d8a0edc61d558.tar.gz bcm5719-llvm-878ae0188919c0499ce2623cf50d8a0edc61d558.zip |
This patch stops lldb from loading a .lldbinit file from the current
working directory by default -- a typical security problem that we
need to be more conservative about.
It adds a new target setting, target.load-cwd-lldbinit which may
be true (always read $cwd/.lldbinit), false (never read $cwd/.lldbinit)
or warn (warn if there is a $cwd/.lldbinit and don't read it). The
default is set to warn. If this is met with unhappiness, we can look
at changing the default to true (to match current behavior) on a
different platform.
This does not affect reading of ~/.lldbinit - that will still be read,
as before. If you run lldb in your home directory, it will not warn
about the presence of a .lldbinit file there.
I had to add two SB API - SBHostOS::GetUserHomeDirectory and
SBFileSpec::AppendPathComponent - for the lldb driver code to be
able to get the home directory path in an OS neutral manner.
The warning text is
There is a .lldbinit file in the current directory which is not being read.
To silence this warning without sourcing in the local .lldbinit,
add the following to the lldbinit file in your home directory:
settings set target.load-cwd-lldbinit false
To allow lldb to source .lldbinit files in the current working directory,
set the value of this variable to true. Only do so if you understand and
accept the security risk.
<rdar://problem/24199163>
llvm-svn: 261280
Diffstat (limited to 'lldb/source/Interpreter/CommandInterpreter.cpp')
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index bab12462489..e31b3367720 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -2319,12 +2319,44 @@ CommandInterpreter::SourceInitFile (bool in_cwd, CommandReturnObject &result) FileSpec init_file; if (in_cwd) { - // In the current working directory we don't load any program specific - // .lldbinit files, we only look for a "./.lldbinit" file. - if (m_skip_lldbinit_files) - return; + ExecutionContext exe_ctx(GetExecutionContext()); + Target *target = exe_ctx.GetTargetPtr(); + if (target) + { + // In the current working directory we don't load any program specific + // .lldbinit files, we only look for a ".lldbinit" file. + if (m_skip_lldbinit_files) + return; - init_file.SetFile ("./.lldbinit", true); + LoadCWDlldbinitFile should_load = target->TargetProperties::GetLoadCWDlldbinitFile (); + if (should_load == eLoadCWDlldbinitWarn) + { + FileSpec dot_lldb (".lldbinit", true); + llvm::SmallString<64> home_dir_path; + llvm::sys::path::home_directory (home_dir_path); + FileSpec homedir_dot_lldb (home_dir_path.c_str(), false); + homedir_dot_lldb.AppendPathComponent (".lldbinit"); + homedir_dot_lldb.ResolvePath (); + if (dot_lldb.Exists () + && dot_lldb.GetDirectory() != homedir_dot_lldb.GetDirectory()) + { + result.AppendErrorWithFormat ( + "There is a .lldbinit file in the current directory which is not being read.\n" + "To silence this warning without sourcing in the local .lldbinit,\n" + "add the following to the lldbinit file in your home directory:\n" + " settings set target.load-cwd-lldbinit false\n" + "To allow lldb to source .lldbinit files in the current working directory,\n" + "set the value of this variable to true. Only do so if you understand and\n" + "accept the security risk."); + result.SetStatus (eReturnStatusFailed); + return; + } + } + else if (should_load == eLoadCWDlldbinitTrue) + { + init_file.SetFile ("./.lldbinit", true); + } + } } else { |