Repository navigation
Quote a list for cmd.exe itself the way it's quoted for a batch file - #51
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong: batch-file quoting (
""for a quote, line breaks refused) only applied whenFilePathended in.bator.cmd.cmd.exeitself given a list got the ordinary\"quoting, whichcmd.exedoesn't honor. So-FilePath cmd.exe -Arguments @('/d', '/c', 'echo', 'a" & echo INJECTED & "')ran the second command, and an element holding&was split there (a&branb). A list is the natural way to pass a file name or user value, even though the README said to givecmd.exe /cone string.What changed:
FilePathofcmdorcmd.exe(any folder, any case, trailing dots ignored) gets the same quoting as a batch file. Like a batch file, an element with a line break is now an error for it.ConvertTo-PkArgumentStringhelp say so. The README also says what's still out of reach:cmd.exestrips the quotes from a program path with spaces after/c, so for one of those, give it one string with/s. That was already true with the old quoting.Tested: new harness assertions, all failing before the fix on 5.1:
cmd.exe /d /c <argv-printer>given the same list as the existing%*test (quotes,\", trailing backslashes, spaces,&) gets it through exactly. Before the fixa&bcame out as[a].cmd.exe /d /c echo, under four spellings of the name (full path,cmd,CMD.EXE, upper case with a trailing dot). Before the fix 28 of 28 ran the injected command; now none, and every probe ran.Invoke-PkProcessBatchwithFilePath = 'cmd.exe'.The spaced-path limit was checked by hand: a list gave no output, and the one-string
/s /cform worked. Full harness passes on Windows PowerShell 5.1 and PowerShell 7.🤖 Generated with Claude Code