Skip to content

Commit 868c7ce

Browse files
committed
mingw: work around incorrect standard handles
For some reason, when being called via TortoiseGit the standard handles can take on the value (HANDLE)-2 (which is not a legal value, according to the documentation). Nevertheless, CreateProcess() works with hStdInput set to this value. But our new code to restrict which file handles get inherited by spawned processes apparently does *not* work with such values, erroring out with `ERROR_INVALID_PARAMETER`. Let's just disallow "negative" handles, and hopefully this will work around the issue. This addresses git-for-windows#1481 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 0922cb3 commit 868c7ce

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

compat/mingw.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1662,12 +1662,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16621662
si.StartupInfo.hStdError = winansi_get_osfhandle(fherr);
16631663

16641664
/* The list of handles cannot contain duplicates */
1665-
if (si.StartupInfo.hStdInput != INVALID_HANDLE_VALUE)
1665+
if ((intptr_t)si.StartupInfo.hStdInput >= 0)
16661666
stdhandles[stdhandles_count++] = si.StartupInfo.hStdInput;
1667-
if (si.StartupInfo.hStdOutput != INVALID_HANDLE_VALUE &&
1667+
if ((intptr_t)si.StartupInfo.hStdOutput >= 0 &&
16681668
si.StartupInfo.hStdOutput != si.StartupInfo.hStdInput)
16691669
stdhandles[stdhandles_count++] = si.StartupInfo.hStdOutput;
1670-
if (si.StartupInfo.hStdError != INVALID_HANDLE_VALUE &&
1670+
if ((intptr_t)si.StartupInfo.hStdError >= 0 &&
16711671
si.StartupInfo.hStdError != si.StartupInfo.hStdInput &&
16721672
si.StartupInfo.hStdError != si.StartupInfo.hStdOutput)
16731673
stdhandles[stdhandles_count++] = si.StartupInfo.hStdError;

0 commit comments

Comments
 (0)