Repository navigation
Conversation
Windows only treats backslashes specially when they precede a double quote, so escaping every backslash handed the child process doubled backslashes. A quote opened for trailing whitespace was also left open, joining that argument with the next one. With the exec-based ssh transport the doubled backslash breaks the '\'' quoting of the repository path for the remote shell, so a path containing a single quote could end the quoting and run commands. Emit backslashes literally, doubling them only before a quote, and close any open quote at the end of each argument.
This branch has not been deployed
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.
git_process__cmdlineoutput fed back throughCommandLineToArgvW, with the remote commandssh_execbuilds for the pathx'; echo INJECTED; ':Windows only gives backslashes a meaning when they precede a double quote; anywhere else they are literal. The encoder escapes every backslash, so the child sees each one doubled. For
ssh_execthat turns the'\''used to quote a single quote in the repository path into'\\'', which ends the quoting in the remote shell, so an ssh URL path containing'(a submodule URL, for instance) runs commands on the remote side. It affects Windows builds withUSE_SSH=exec. The same function also left a quote open after an argument ending in whitespace, joining it with the next argument.The fix emits backslashes literally, doubles them only before a quote (literal or one that toggles quoting), and closes any open quote at the end of each argument. Round-tripping 20000 random argument vectors through
CommandLineToArgvWgave 13639 mismatches before and 0 after. The existingcmdline_escapes_backslashexpectations encoded the doubling, so they are corrected; two tests are added for backslashes before a quote and for the unterminated quote.util_testspasses (VS 2022, x64,USE_SSH=exec).