Skip to content

Windows cmd.run: gate prepend_cmd quoting for win_runas only; fix test_cmd_builtins#69002

Open
twangboy wants to merge 9 commits intosaltstack:3006.xfrom
twangboy:default_shell
Open

Windows cmd.run: gate prepend_cmd quoting for win_runas only; fix test_cmd_builtins#69002
twangboy wants to merge 9 commits intosaltstack:3006.xfrom
twangboy:default_shell

Conversation

@twangboy
Copy link
Copy Markdown
Contributor

What does this PR do?

Summary

Restores the pre-3006 cmd.exe /c behavior for the normal subprocess / TimedProc path when python_shell is true and runas is not set: the user payload is not wrapped in the CreateProcess-style “single quoted /c argument” (_cmd_exe_cswitch_quoted_argument). That outer wrapping is only needed for win_runas / CreateProcessWithTokenW, where the whole command must be one argument so &, |, etc. are not parsed at the wrong level.

This fixes functional failures in test_cmd_builtins for edge cmd patterns (set /p, special characters) that depend on unquoted /c semantics.

Code changes

  • salt/platform/win.py (​salt/platform/win.py​)

    • prepend_cmd(..., quote_c_payload=True)
    • False → {win_shell} /c {args} (list → list2cmdline first)
    • True (default) → existing quoted payload for CreateProcess / win_runas
  • salt/modules/cmdmod.py (​salt/modules/cmdmod.py​)

    • prepend_cmd(..., quote_c_payload=bool(runas)) when preparing cmd.exe with python_shell or runas
    • Comment clarifies quoted /c is for the win_runas path

Tests

  • tests/pytests/unit/platform/test_win.py (​tests/pytests/unit/platform/test_win.py​)

    • Explicit quote_c_payload=True in the existing CreateProcess-style test
    • test_prepend_cmd_unquoted_payload for the subprocess-style line
  • tests/pytests/functional/modules/cmd/test_run_win.py (tests/pytests/functional/modules/cmd/test_run_win.py​)

    • Shared _CMD_BUILTINS_CORE / _CMD_BUILTINS_EDGE
    • test_cmd_builtins: all cases (core + edge)
    • test_cmd_builtins_runas: core only; edge cases stay in the non-runas test, with a short note that win_runas still uses a quoted /c payload, so those lines are not expected to match unquoted cmd behavior (full parity would need a different approach, e.g. temp script file).

Related context

  • Complements earlier work: runas + cmd compound commands, win_runas pipe draining / resume, get_user_sid for numeric usernames, etc.

What issues does this PR fix or reference?

Fixes #68448

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

@twangboy twangboy requested a review from a team as a code owner April 27, 2026 22:44
@twangboy twangboy self-assigned this Apr 27, 2026
@twangboy twangboy added the test:full Run the full test suite label Apr 27, 2026
@twangboy twangboy added this to the Sulpher v3006.24 milestone Apr 27, 2026
dwoz
dwoz previously approved these changes Apr 28, 2026
sujitdb
sujitdb previously approved these changes Apr 28, 2026
Copy link
Copy Markdown
Collaborator

@sujitdb sujitdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Collaborator

@sujitdb sujitdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants