diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2012-01-19 16:41:17 -0500 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2012-01-19 16:41:17 -0500 |
commit | 6fddfab6dd8e49dcbf4933bde23dbcdfe3e213db (patch) | |
tree | 156bc71767d6043bfc465be7e413b736f1a5616f /indra/llcommon | |
parent | 1ed5bb3adaea0b4fee1e471575459039df8ced2f (diff) |
Try to fix argument quoting on Windows.
Despite LLProcessLauncher's list-of-argument-strings API, on Windows it must
ram them all into a single command-line string anyway. This means that if
arguments contain spaces (or anything else that would confuse Windows command-
line parsing), the target process won't receive the intended arguments.
Introduce double quotes for any arguments not already double-quoted by caller.
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/llprocesslauncher.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/indra/llcommon/llprocesslauncher.cpp b/indra/llcommon/llprocesslauncher.cpp index e1af49c2fb..adad3546fe 100644 --- a/indra/llcommon/llprocesslauncher.cpp +++ b/indra/llcommon/llprocesslauncher.cpp @@ -75,6 +75,28 @@ void LLProcessLauncher::addArgument(const std::string &arg) #if LL_WINDOWS +static std::string quote(const std::string& str) +{ + std::string::size_type len(str.length()); + // If the string is already quoted, assume user knows what s/he's doing. + if (len >= 2 && str[0] == '"' && str[len-1] == '"') + { + return str; + } + + // Not already quoted: do it. + std::string result("\""); + for (std::string::const_iterator ci(str.begin()), cend(str.end()); ci != cend; ++ci) + { + if (*ci == '"') + { + result.append("\\"); + } + result.append(*ci); + } + return result + "\""; +} + int LLProcessLauncher::launch(void) { // If there was already a process associated with this object, kill it. @@ -87,11 +109,11 @@ int LLProcessLauncher::launch(void) STARTUPINFOA sinfo; memset(&sinfo, 0, sizeof(sinfo)); - std::string args = mExecutable; + std::string args = quote(mExecutable); for(int i = 0; i < (int)mLaunchArguments.size(); i++) { args += " "; - args += mLaunchArguments[i]; + args += quote(mLaunchArguments[i]); } // So retarded. Windows requires that the second parameter to CreateProcessA be a writable (non-const) string... |