Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A couple fixes for the credential helper selector #319

Merged
merged 2 commits into from
Dec 11, 2020

Conversation

dscho
Copy link
Member

@dscho dscho commented Dec 10, 2020

In a conversation with @mjcheetham I realized that neither %s nor %S are appropriate format specifiers for wide-character string arguments in printf()/wprintf() calls. Instead, %ls is the best option.

After fixing this, I noticed in my tests that the helper selector constructed a command line with improperly quoted paths. That's the other fix included in this PR.

dscho added 2 commits December 9, 2020 15:40
In b64ba6a (credential-helper-selector: use the correct format
specifier for Unicode, 2020-08-11), we changed all those `%s` to `%S` to
make sure that wide-character string parameters were handled correctly.

While this does appear to work correctly, it is a bit fragile because
`%S` is fragile: there are two standards defining its behavior, and they
disagree.

The Microsoft convention is that `%S` in a wide-character format string
means that the argument is a multi-byte string:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions

This is the opposite interpretation of POSIX, which defines `%S` to
indicate a wide-character string argument, whether specified in a
multi-byte format string or a wide-character format string:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fwprintf.html

However, there is one safe recourse: if you want to print wide-character
strings via `printf()` or `wprintf()`, just use the `%ls` format
specifier. That works with POSIX semantics as well as with Microsoft
semantics.

So let's do exactly that.

Signed-off-by: Johannes Schindelin <[email protected]>
In general, we cannot guarantee that the path of the chosen credential
helper has no special characters in it. Therefore, we have to quote it.

This can be verified by putting a credential manager into a directory
whose path contains a space (such as `C:\Program Files\...`), adding
that directory to the `PATH`, and then calling the
credential-helper-selector e.g. with the argument `version` (which at
least Git Credential Manager Core understands).

While the executable will still be spawned correctly, it will then fail
to parse its command line correctly.

The symptom looks like this:

	Unrecognized command 'Files'.

	usage: git-credential-manager-core <command>

	  Available commands:
	    erase
	    get
	    store

	    configure [--system]
	    unconfigure [--system]

	    --version, version
	    --help, -h, -?

Let's quote the absolute path correctly when copying it into the command
line.

Signed-off-by: Johannes Schindelin <[email protected]>
@dscho dscho requested a review from mjcheetham December 10, 2020 11:15
Copy link
Member

@mjcheetham mjcheetham left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@dscho dscho merged commit 8ce6ef2 into git-for-windows:main Dec 11, 2020
@dscho dscho deleted the credential-helper-selector-fixes branch December 11, 2020 12:00
dscho added a commit that referenced this pull request Dec 11, 2020
The credential-helper selector (which is the
default credential helper in the Portable version
of Git for Windows) [now handles paths with spaces
correctly](#319).

Signed-off-by: Johannes Schindelin <[email protected]>
Copy link

@abuwely abuwely left a comment

Choose a reason for hiding this comment

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

abuwely

@Ollodriss

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants