Skip to content

Commit

Permalink
mingw: work around incorrect standard handles
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dscho committed Feb 7, 2018
1 parent 0922cb3 commit 868c7ce
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1662,12 +1662,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
si.StartupInfo.hStdError = winansi_get_osfhandle(fherr);

/* The list of handles cannot contain duplicates */
if (si.StartupInfo.hStdInput != INVALID_HANDLE_VALUE)
if ((intptr_t)si.StartupInfo.hStdInput >= 0)
stdhandles[stdhandles_count++] = si.StartupInfo.hStdInput;
if (si.StartupInfo.hStdOutput != INVALID_HANDLE_VALUE &&
if ((intptr_t)si.StartupInfo.hStdOutput >= 0 &&
si.StartupInfo.hStdOutput != si.StartupInfo.hStdInput)
stdhandles[stdhandles_count++] = si.StartupInfo.hStdOutput;
if (si.StartupInfo.hStdError != INVALID_HANDLE_VALUE &&
if ((intptr_t)si.StartupInfo.hStdError >= 0 &&
si.StartupInfo.hStdError != si.StartupInfo.hStdInput &&
si.StartupInfo.hStdError != si.StartupInfo.hStdOutput)
stdhandles[stdhandles_count++] = si.StartupInfo.hStdError;
Expand Down

0 comments on commit 868c7ce

Please sign in to comment.