microsoft / microsoft/sudo

Sudo doesn't preserves the command line as-is

Open
#117 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Bug Needs-Triage
Dominant language
Rust
Stars
5.9k
Forks
180
Avg merge
1d 7h
Merged PRs (30d)
2

Description

Sudo for Windows version

1.0.1

Windows build number

10.0.26100.2605

Other Software
Steps to reproduce

Start the shell cmd.exe and run these commandlines.

1a)

C:\MeinPath\get-command-line.exe hello    world

1b)

sudo run --inline -- C:\MeinPath\get-command-line.exe hello    world

Replace C:\MeinPath\get-command-line.exe with path to your commandline-outputting tool.

Note the four space characters between “hello” and “world”.

2a)

C:\MeinPath\get-command-line.exe hello"    "world

2b)

sudo run --inline -- C:\MeinPath\get-command-line.exe hello"    "world
Expected Behavior

The expected output of command 1a) is:

C:\MeinPath\get-command-line.exe  hello"    "world

and of 1b):

"C:\MeinPath\get-command-line.exe" hello    world

with four spaces between “hello” and “world”!

The expected output of command 2a) is:

C:\MeinPath\get-command-line.exe  hello"    "world

and of 2b):

"C:\MeinPath\get-command-line.exe" hello"    "world

with the quote characters inbetween “hello” and “world”.

cmd preserves the command-line with all spaces, which was entered by the user, when it builds the lpCommandLine argument for CreateProcessW().

Actual Behavior

The actual behavior is, that the output of 1b) is:

"C:\MeinPath\get-command-line.exe" hello world

without four spaces between “hello” and “world”!

And the output of 2b) is actually:

"C:\MeinPath\get-command-line.exe" "hello    world"

with the quote characters around “hello world”.

See this image:

Image

Comments

The reason that I report this bug, is, that not every program on Windows uses the same logic to split commandline into multiple arguments.
The usual convetion is to do it like the Microsoft C-Runtime. But some programs like cmd.exe itself, do it differently.

If the commandline after the two dashes -- is preserved as-is, it would be the best, I think.

Another helpful program to debug these things is my Rust program "create-process-rust".

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two command pairs in cmd.exe with sudo run --inline -- and compare the output from GetCommandLineW(). Read the CreateProcessW command-line behavior and the Microsoft C Runtime parsing conventions referenced in the report. Done means inline commands preserve the original spacing and embedded quotes shown in the expected outputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.