From 545c43ec0f089ac08b16085ee78c63d080323a0e Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett (MSFT)" Date: Fri, 10 Jan 2020 17:48:05 -0800 Subject: [PATCH] when spawning a pty, be sure to provide & escape conhost's path (#4172) Fixes #4061. Co-authored-by: Michael Niksa (cherry picked from commit 2712e41cad2abcfe627934e41e713ea132a659de) --- src/winconpty/winconpty.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/winconpty/winconpty.cpp b/src/winconpty/winconpty.cpp index a09d952f1de..5a68c8e50d7 100644 --- a/src/winconpty/winconpty.cpp +++ b/src/winconpty/winconpty.cpp @@ -82,7 +82,8 @@ HRESULT _CreatePseudoConsole(const HANDLE hToken, RETURN_IF_WIN32_BOOL_FALSE(CreatePipe(signalPipeConhostSide.addressof(), signalPipeOurSide.addressof(), &sa, 0)); RETURN_IF_WIN32_BOOL_FALSE(SetHandleInformation(signalPipeConhostSide.get(), HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)); - const wchar_t* pwszFormat = L"%s --headless %s--width %hu --height %hu --signal 0x%x --server 0x%x"; + // GH4061: Ensure that the path to executable in the format is escaped so C:\Program.exe cannot collide with C:\Program Files + const wchar_t* pwszFormat = L"\"%s\" --headless %s--width %hu --height %hu --signal 0x%x --server 0x%x"; // This is plenty of space to hold the formatted string wchar_t cmd[MAX_PATH]{}; const BOOL bInheritCursor = (dwFlags & PSEUDOCONSOLE_INHERIT_CURSOR) == PSEUDOCONSOLE_INHERIT_CURSOR; @@ -149,7 +150,7 @@ HRESULT _CreatePseudoConsole(const HANDLE hToken, if (hToken == INVALID_HANDLE_VALUE || hToken == nullptr) { // Call create process - RETURN_IF_WIN32_BOOL_FALSE(CreateProcessW(nullptr, + RETURN_IF_WIN32_BOOL_FALSE(CreateProcessW(_ConsoleHostPath(), cmd, nullptr, nullptr, @@ -164,7 +165,7 @@ HRESULT _CreatePseudoConsole(const HANDLE hToken, { // Call create process RETURN_IF_WIN32_BOOL_FALSE(CreateProcessAsUserW(hToken, - nullptr, + _ConsoleHostPath(), cmd, nullptr, nullptr,