diff options
author | Enrico Granata <egranata@apple.com> | 2016-04-04 22:46:38 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2016-04-04 22:46:38 +0000 |
commit | 7a37df3fc3b39774004b9e8fcfdc86b579a40c1e (patch) | |
tree | f0ba6a675c494e4a7c553397a242b1d0c8fcca42 /lldb/source/Interpreter | |
parent | 769b5fd546c55a1c37cb037e3fe6c249b953b1c3 (diff) | |
download | bcm5719-llvm-7a37df3fc3b39774004b9e8fcfdc86b579a40c1e.tar.gz bcm5719-llvm-7a37df3fc3b39774004b9e8fcfdc86b579a40c1e.zip |
Improve the way LLDB escapes arguments before passing them to the shell
Teach LLDB that different shells have different characters they are sensitive to, and use that knowledge to do shell-aware escaping
This helps solve a class of problems on OS X where LLDB would try to launch via sh, and run into problems if the command line being passed to the inferior contained such special markers (hint: the shell would error out and we'd fail to launch)
This makes those launch scenarios work transparently via shell expansion
Slightly improve the error message when this kind of failure occurs to at least suggest that the user try going through 'process launch' directly
Fixes rdar://problem/22749408
llvm-svn: 265357
Diffstat (limited to 'lldb/source/Interpreter')
-rw-r--r-- | lldb/source/Interpreter/Args.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp index 81e6b0aa1db..f6c018f4262 100644 --- a/lldb/source/Interpreter/Args.cpp +++ b/lldb/source/Interpreter/Args.cpp @@ -887,14 +887,43 @@ Args::StringToVersion (const char *s, uint32_t &major, uint32_t &minor, uint32_t } const char * -Args::GetShellSafeArgument (const char *unsafe_arg, std::string &safe_arg) +Args::GetShellSafeArgument (const FileSpec& shell, + const char *unsafe_arg, + std::string &safe_arg) { + struct ShellDescriptor + { + ConstString m_basename; + const char* m_escapables; + }; + + static ShellDescriptor g_Shells[] = { + {ConstString("bash")," '\"<>()&"}, + {ConstString("tcsh")," '\"<>()&$"}, + {ConstString("sh")," '\"<>()&"} + }; + + // safe minimal set + const char* escapables = " '\""; + + if (auto basename = shell.GetFilename()) + { + for (const auto& Shell : g_Shells) + { + if (Shell.m_basename == basename) + { + escapables = Shell.m_escapables; + break; + } + } + } + safe_arg.assign (unsafe_arg); size_t prev_pos = 0; while (prev_pos < safe_arg.size()) { // Escape spaces and quotes - size_t pos = safe_arg.find_first_of(" '\"", prev_pos); + size_t pos = safe_arg.find_first_of(escapables, prev_pos); if (pos != std::string::npos) { safe_arg.insert (pos, 1, '\\'); @@ -906,7 +935,6 @@ Args::GetShellSafeArgument (const char *unsafe_arg, std::string &safe_arg) return safe_arg.c_str(); } - int64_t Args::StringToOptionEnum (const char *s, OptionEnumValueElement *enum_values, int32_t fail_value, Error &error) { |