From 6fddfab6dd8e49dcbf4933bde23dbcdfe3e213db Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Thu, 19 Jan 2012 16:41:17 -0500
Subject: [PATCH] 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.

---
 indra/llcommon/llprocesslauncher.cpp | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/indra/llcommon/llprocesslauncher.cpp b/indra/llcommon/llprocesslauncher.cpp
index e1af49c2fb5..adad3546fe7 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...
-- 
GitLab