Skip to content

Commit 117b76b

Browse files
committed
fixup! mingw: restrict file handle inheritance only on Windows 7 and later
Let's drop this patch: Git for Windows dropped supporting Windows 7 (and Windows 8) directly after Git for Windows v2.46.2. For full details, see https://gitforwindows.org/requirements#windows-version. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent d20d8cd commit 117b76b

File tree

2 files changed

+4
-70
lines changed

2 files changed

+4
-70
lines changed

Documentation/config/core.adoc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -704,12 +704,6 @@ core.unsetenvvars::
704704
Defaults to `PERL5LIB` to account for the fact that Git for
705705
Windows insists on using its own Perl interpreter.
706706

707-
core.restrictinheritedhandles::
708-
Windows-only: override whether spawned processes inherit only standard
709-
file handles (`stdin`, `stdout` and `stderr`) or all handles. Can be
710-
`auto`, `true` or `false`. Defaults to `auto`, which means `true` on
711-
Windows 7 and later, and `false` on older Windows versions.
712-
713707
core.createObject::
714708
You can set this to 'link', in which case a hardlink followed by
715709
a delete of the source are used to make sure that object creation

compat/mingw.c

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ enum hide_dotfiles_type {
274274
HIDE_DOTFILES_DOTGITONLY
275275
};
276276

277-
static int core_restrict_inherited_handles = -1;
278277
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
279278
static char *unset_environment_variables;
280279
int core_fscache;
@@ -325,15 +324,6 @@ int mingw_core_config(const char *var, const char *value,
325324
return 0;
326325
}
327326

328-
if (!strcmp(var, "core.restrictinheritedhandles")) {
329-
if (value && !strcasecmp(value, "auto"))
330-
core_restrict_inherited_handles = -1;
331-
else
332-
core_restrict_inherited_handles =
333-
git_config_bool(var, value);
334-
return 0;
335-
}
336-
337327
return 0;
338328
}
339329

@@ -2060,7 +2050,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20602050
const char *dir, const char *prepend_cmd,
20612051
int fhin, int fhout, int fherr)
20622052
{
2063-
static int restrict_handle_inheritance = -1;
20642053
STARTUPINFOEXW si;
20652054
PROCESS_INFORMATION pi;
20662055
LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL;
@@ -2080,16 +2069,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20802069
/* Make sure to override previous errors, if any */
20812070
errno = 0;
20822071

2083-
if (restrict_handle_inheritance < 0)
2084-
restrict_handle_inheritance = core_restrict_inherited_handles;
2085-
/*
2086-
* The following code to restrict which handles are inherited seems
2087-
* to work properly only on Windows 7 and later, so let's disable it
2088-
* on Windows Vista and 2008.
2089-
*/
2090-
if (restrict_handle_inheritance < 0)
2091-
restrict_handle_inheritance = GetVersion() >> 16 >= 7601;
2092-
20932072
do_unset_environment_variables();
20942073

20952074
/* Determine whether or not we are associated to a console */
@@ -2195,7 +2174,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21952174
wenvblk = make_environment_block(deltaenv);
21962175

21972176
memset(&pi, 0, sizeof(pi));
2198-
if (restrict_handle_inheritance && stdhandles_count &&
2177+
if (stdhandles_count &&
21992178
(InitializeProcThreadAttributeList(NULL, 1, 0, &size) ||
22002179
GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
22012180
(attr_list = (LPPROC_THREAD_ATTRIBUTE_LIST)
@@ -2216,52 +2195,13 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
22162195
&si.StartupInfo, &pi);
22172196

22182197
/*
2219-
* On Windows 2008 R2, it seems that specifying certain types of handles
2220-
* (such as FILE_TYPE_CHAR or FILE_TYPE_PIPE) will always produce an
2221-
* error. Rather than playing finicky and fragile games, let's just try
2222-
* to detect this situation and simply try again without restricting any
2223-
* handle inheritance. This is still better than failing to create
2224-
* processes.
2198+
* On the off-chance that something with the file handle restriction
2199+
* went wrong, silently fall back to trying without it.
22252200
*/
2226-
if (!ret && restrict_handle_inheritance && stdhandles_count) {
2201+
if (!ret && stdhandles_count) {
22272202
DWORD err = GetLastError();
22282203
struct strbuf buf = STRBUF_INIT;
22292204

2230-
if (err != ERROR_NO_SYSTEM_RESOURCES &&
2231-
/*
2232-
* On Windows 7 and earlier, handles on pipes and character
2233-
* devices are inherited automatically, and cannot be
2234-
* specified in the thread handle list. Rather than trying
2235-
* to catch each and every corner case (and running the
2236-
* chance of *still* forgetting a few), let's just fall
2237-
* back to creating the process without trying to limit the
2238-
* handle inheritance.
2239-
*/
2240-
!(err == ERROR_INVALID_PARAMETER &&
2241-
GetVersion() >> 16 < 9200) &&
2242-
!getenv("SUPPRESS_HANDLE_INHERITANCE_WARNING")) {
2243-
DWORD fl = 0;
2244-
int i;
2245-
2246-
setenv("SUPPRESS_HANDLE_INHERITANCE_WARNING", "1", 1);
2247-
2248-
for (i = 0; i < stdhandles_count; i++) {
2249-
HANDLE h = stdhandles[i];
2250-
strbuf_addf(&buf, "handle #%d: %p (type %lx, "
2251-
"handle info (%d) %lx\n", i, h,
2252-
GetFileType(h),
2253-
GetHandleInformation(h, &fl),
2254-
fl);
2255-
}
2256-
strbuf_addstr(&buf, "\nThis is a bug; please report it "
2257-
"at\nhttps://github.com/git-for-windows/"
2258-
"git/issues/new\n\n"
2259-
"To suppress this warning, please set "
2260-
"the environment variable\n\n"
2261-
"\tSUPPRESS_HANDLE_INHERITANCE_WARNING=1"
2262-
"\n");
2263-
}
2264-
restrict_handle_inheritance = 0;
22652205
flags &= ~EXTENDED_STARTUPINFO_PRESENT;
22662206
ret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL,
22672207
TRUE, flags, wenvblk, dir ? wdir : NULL,

0 commit comments

Comments
 (0)