Skip to content

Commit

Permalink
git (git-wrapper): when standing in for a builtin, check the case
Browse files Browse the repository at this point in the history
Misspelling the commant `git status` as `GIT STATUS` will fail due to
the incorrect case: `git.exe` would not think that this is a builtin,
and execute the dashed `git-STATUS.exe`, which in turn would match
`git-status.exe` on Windows (because case-insensitive file system), and
that would be the Git wrapper, which would then call `git.exe STATUS`
again.

This fixes git-for-windows/git#1496.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Mar 15, 2018
1 parent 10b5eef commit caca739
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mingw-w64-git/git-wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ int main(void)
prefix_args_len = wcslen(buffer);
}
else if (!wcsnicmp(basename, L"git-", 4)) {
LPCWSTR builtin_env = L"GIT_WRAPPER_BUILTIN_NAME";
LPWSTR p;
int len;

needs_env_setup = 0;

/* Call a builtin */
Expand All @@ -565,6 +569,26 @@ int main(void)
if (!wcsicmp(prefix_args + prefix_args_len - 4, L".exe"))
prefix_args_len -= 4;

len = GetEnvironmentVariableW(builtin_env, NULL, 0);
if (len == prefix_args_len + 1) {
p = malloc(sizeof(WCHAR) * len);
if (!p ||
!GetEnvironmentVariableW(builtin_env, p, len) ||
!wcsnicmp(p, prefix_args, prefix_args_len)) {
fwprintf(stderr,
L"Invalid builtin name (incorrect "
"case?): '%.*s'\n",
prefix_args_len, prefix_args);
exit(1);
}
free(p);
}
p = malloc(sizeof(WCHAR) * (prefix_args_len + 1));
memcpy(p, prefix_args, sizeof(WCHAR) * prefix_args_len);
p[prefix_args_len] = L'\0';
SetEnvironmentVariableW(builtin_env, p);
free(p);

/* set the default exe module */
wcscpy(exe, exepath);
PathAppend(exe, L"git.exe");
Expand Down

0 comments on commit caca739

Please sign in to comment.