From ca0393b4b2ec4699a4d70010c44c0fc3c02c0fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Tue, 28 Nov 2023 10:03:23 -0500 Subject: [PATCH] fix MsRdpEx_LaunchProcess when launch path has spaces --- dll/RdpProcess.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/dll/RdpProcess.cpp b/dll/RdpProcess.cpp index 6a3f83d..cbb66c5 100644 --- a/dll/RdpProcess.cpp +++ b/dll/RdpProcess.cpp @@ -237,7 +237,7 @@ class CMsRdpExProcess : public IMsRdpExProcess { HRESULT hr = S_OK; uint32_t appPathId = 0; - char szCommandLine[2048]; + char* lpCommandLine = NULL; STARTUPINFOA* startupInfo; PROCESS_INFORMATION* processInfo; const char* axNameEnv = NULL; @@ -279,15 +279,14 @@ class CMsRdpExProcess : public IMsRdpExProcess lpApplicationName = MsRdpEx_GetPath(appPathId); } - ZeroMemory(szCommandLine, sizeof(szCommandLine)); + char quotedAppFilePath[MSRDPEX_MAX_PATH]; + sprintf_s(quotedAppFilePath, MSRDPEX_MAX_PATH - 1, "\"%s\"", lpApplicationName); - for (int i = 1; i < argc; i++) - { - strncat(szCommandLine, argv[i], sizeof(szCommandLine) - 1); - strncat(szCommandLine, " ", sizeof(szCommandLine) - 1); - } + char* argv0 = argv[0]; + argv[0] = (char*) quotedAppFilePath; + lpCommandLine = MsRdpEx_StringJoin(argv, argc, ' '); + argv[0] = argv0; - char* lpCommandLine = szCommandLine; DWORD dwCreationFlags = CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED; const char* lpDllName = MsRdpEx_GetPath(MSRDPEX_LIBRARY_PATH); @@ -306,6 +305,8 @@ class CMsRdpExProcess : public IMsRdpExProcess NULL /* pfCreateProcessW */ ); + free(lpCommandLine); + if (!fSuccess) { hr = E_FAIL; goto exit;