mxc icon indicating copy to clipboard operation
mxc copied to clipboard

[IsolationSession] A command line that starts with a quote loses its first and last quote

Open adpa-ms opened this issue 4 weeks ago • 2 comments

Relevant area(s)

Windows

Brief description of your issue

The IsolationSession backend launches cmd.exe with the arguments /c <commandLine> (src/mxc-sdk/src/backends/isolation_session/common/process_options.rs :: build_process_options) for every run except a PTY run. When the command line starts with a quote and contains more than two quotes, cmd.exe removes the first and the last quote before running it, as cmd /? documents, so a quoted program followed by a quoted argument fails. docs/development/architecture/backends/isolation-session/oneshot.md describes the wrapper as cmd.exe /c "...". The Windows Sandbox guest has the same defect in separate code (#1643).

Steps to reproduce

Start cmd.exe with the arguments /c <commandLine>, as build_process_options does, on Windows 11 with each command line:

  1. "C:\Windows\System32\cmd.exe" /c "echo hello"
  2. "C:\Program Files\PowerShell\7\pwsh.exe" "--version"

Expected behavior

  1. hello, exit code 0.
  2. The PowerShell version, exit code 0.

Actual behavior

  1. The directory name is invalid., exit code 1.
  2. 'C:\Program' is not recognized as an internal or external command, operable program or batch file., exit code 1.

adpa-ms avatar Nov 03 '26 18:11 adpa-ms

Seems like fixing this would involve introducing a rule that people might be working around already.

A generalized solution for this could be wrapping the config's commandLine field in protective quotes before we pass it to cmd.exe internally, so cmd.exe won't touch any quotes from the caller's original command. However, some people may be working around this already by wrapping their commandLines in protective quotes as part of the config construction process. I can't really foresee a way to detect whether a commandLine with " as the first and last character is a fully-quoted command or not within MXC without adding some kind of more complicated command-line parser, which I don't know if we should take on.

Pausing development right now so that we can talk about this potential compatibility issue going forward.

daamenik avatar Nov 12 '26 22:11 daamenik

Addressing this issue in two PRs:

The first (#1773) clarifies the current commandLine handling more clearly in the documentation.

The second will be a breaking change to wrap the commandLine in protective quotes, as originally specified in oneshot.md, implemented when breaking changes can be accepted.

daamenik avatar Nov 14 '26 00:11 daamenik