run-command: avoid NULL dereference for missing Windows shell - #6358
Conversation
When Git's native Windows environment omits its usr/bin directory from
PATH, locate_in_PATH("sh") returns NULL. git_shell_path() passes that value
to convert_slashes(), causing git-remote-https.exe to terminate with an
access violation while preparing a credential helper.
Report the missing shell as a fatal Git error instead. This avoids the
NULL-pointer dereference and adds a Windows-only regression test that
clears PATH inside test-tool and verifies the diagnostic.
Signed-off-by: Peter Kowalczyk <peter@slix.io>
Running Git for Windows in an environment where Therefore, this PR looks like a fix for something that is not considered a bug, but an incorrect usage of |
Summary
On native Windows,
git_shell_path()assumes thatlocate_in_PATH("sh")always succeeds and passes its result directly to
convert_slashes(). Ifshis absent fromPATH, the lookup returnsNULLand Git terminateswith an access violation.
Check the lookup result and report a fatal error instead:
This prevents the NULL dereference. It does not add a shell fallback, so
commands requiring a shell still fail when no shell is available.
Crash analysis
The failure was reproduced in
git-remote-https.exefrom Git for Windows2.55.0.windows.3. ProcDump captured the unhandled exception:
The dump confirms that the faulting instruction attempted to read through
RAXwhileRAXwas zero:Correlation of the surrounding disassembly with the source shows it
loading
"sh", performing the PATH lookup, and then entering the slashconversion. This matches the native Windows implementation:
The reproduced missing-
shcondition therefore leavespasNULL,which is dereferenced by
convert_slashes().Regression test
Add a MINGW-only regression test that clears
PATHinsidetest-tool run-command, callsgit_shell_path(), and verifies that Gitreports the controlled fatal diagnostic instead of crashing.
The helper clears
PATHafter process startup, making the missing-shellcondition deterministic without depending on Windows startup PATH
reconstruction.
Testing
Passed:
git diff --checkt/t0061-run-command.shThe native Windows test suite was not run locally because a Git for

Windows SDK/compiler was unavailable in the test environment. Windows CI
is expected to build the change and run
t0061-run-command.sh.