Skip to content

Commit

Permalink
when spawning a pty, be sure to provide & escape conhost's path (#4172)
Browse files Browse the repository at this point in the history
Fixes #4061.

Co-authored-by: Michael Niksa <[email protected]>
(cherry picked from commit 2712e41)
  • Loading branch information
DHowett committed Jan 24, 2020
1 parent cbdfd0e commit 545c43e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/winconpty/winconpty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -164,7 +165,7 @@ HRESULT _CreatePseudoConsole(const HANDLE hToken,
{
// Call create process
RETURN_IF_WIN32_BOOL_FALSE(CreateProcessAsUserW(hToken,
nullptr,
_ConsoleHostPath(),
cmd,
nullptr,
nullptr,
Expand Down

0 comments on commit 545c43e

Please sign in to comment.