Skip to content

Commit aaa78a7

Browse files
committed
mingw: drop Windows 7-specific work-around
In ac33519 (mingw: restrict file handle inheritance only on Windows 7 and later, 2019-11-22), I introduced code to safe-guard the defense-in-depth handling that restricts handles' inheritance so that it would work with Windows 7, too. Let's revert 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. Actually, on second thought: revert only the part that makes this handle inheritance restriction logic optional and that suggests to open a bug report if it fails, but keep the fall-back to try again without said logic: There have been a few false positives over the past few years (where the warning was triggered e.g. because Defender was still accessing a file that Git wanted to overwrite), and the fall-back logic seems to have helped occasionally in such situations. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 23fec80 commit aaa78a7

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
@@ -696,12 +696,6 @@ core.unsetenvvars::
696696
Defaults to `PERL5LIB` to account for the fact that Git for
697697
Windows insists on using its own Perl interpreter.
698698

699-
core.restrictinheritedhandles::
700-
Windows-only: override whether spawned processes inherit only standard
701-
file handles (`stdin`, `stdout` and `stderr`) or all handles. Can be
702-
`auto`, `true` or `false`. Defaults to `auto`, which means `true` on
703-
Windows 7 and later, and `false` on older Windows versions.
704-
705699
core.createObject::
706700
You can set this to 'link', in which case a hardlink followed by
707701
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
@@ -244,7 +244,6 @@ enum hide_dotfiles_type {
244244
HIDE_DOTFILES_DOTGITONLY
245245
};
246246

247-
static int core_restrict_inherited_handles = -1;
248247
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
249248
static char *unset_environment_variables;
250249

@@ -268,15 +267,6 @@ int mingw_core_config(const char *var, const char *value,
268267
return 0;
269268
}
270269

271-
if (!strcmp(var, "core.restrictinheritedhandles")) {
272-
if (value && !strcasecmp(value, "auto"))
273-
core_restrict_inherited_handles = -1;
274-
else
275-
core_restrict_inherited_handles =
276-
git_config_bool(var, value);
277-
return 0;
278-
}
279-
280270
return 0;
281271
}
282272

@@ -1667,7 +1657,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16671657
const char *dir,
16681658
int prepend_cmd, int fhin, int fhout, int fherr)
16691659
{
1670-
static int restrict_handle_inheritance = -1;
16711660
STARTUPINFOEXW si;
16721661
PROCESS_INFORMATION pi;
16731662
LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL;
@@ -1687,16 +1676,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16871676
/* Make sure to override previous errors, if any */
16881677
errno = 0;
16891678

1690-
if (restrict_handle_inheritance < 0)
1691-
restrict_handle_inheritance = core_restrict_inherited_handles;
1692-
/*
1693-
* The following code to restrict which handles are inherited seems
1694-
* to work properly only on Windows 7 and later, so let's disable it
1695-
* on Windows Vista and 2008.
1696-
*/
1697-
if (restrict_handle_inheritance < 0)
1698-
restrict_handle_inheritance = GetVersion() >> 16 >= 7601;
1699-
17001679
do_unset_environment_variables();
17011680

17021681
/* Determine whether or not we are associated to a console */
@@ -1798,7 +1777,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
17981777
wenvblk = make_environment_block(deltaenv);
17991778

18001779
memset(&pi, 0, sizeof(pi));
1801-
if (restrict_handle_inheritance && stdhandles_count &&
1780+
if (stdhandles_count &&
18021781
(InitializeProcThreadAttributeList(NULL, 1, 0, &size) ||
18031782
GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
18041783
(attr_list = (LPPROC_THREAD_ATTRIBUTE_LIST)
@@ -1819,52 +1798,13 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18191798
&si.StartupInfo, &pi);
18201799

18211800
/*
1822-
* On Windows 2008 R2, it seems that specifying certain types of handles
1823-
* (such as FILE_TYPE_CHAR or FILE_TYPE_PIPE) will always produce an
1824-
* error. Rather than playing finicky and fragile games, let's just try
1825-
* to detect this situation and simply try again without restricting any
1826-
* handle inheritance. This is still better than failing to create
1827-
* processes.
1801+
* On the off-chance that something with the file handle restriction
1802+
* went wrong, silently fall back to trying without it.
18281803
*/
1829-
if (!ret && restrict_handle_inheritance && stdhandles_count) {
1804+
if (!ret && stdhandles_count) {
18301805
DWORD err = GetLastError();
18311806
struct strbuf buf = STRBUF_INIT;
18321807

1833-
if (err != ERROR_NO_SYSTEM_RESOURCES &&
1834-
/*
1835-
* On Windows 7 and earlier, handles on pipes and character
1836-
* devices are inherited automatically, and cannot be
1837-
* specified in the thread handle list. Rather than trying
1838-
* to catch each and every corner case (and running the
1839-
* chance of *still* forgetting a few), let's just fall
1840-
* back to creating the process without trying to limit the
1841-
* handle inheritance.
1842-
*/
1843-
!(err == ERROR_INVALID_PARAMETER &&
1844-
GetVersion() >> 16 < 9200) &&
1845-
!getenv("SUPPRESS_HANDLE_INHERITANCE_WARNING")) {
1846-
DWORD fl = 0;
1847-
int i;
1848-
1849-
setenv("SUPPRESS_HANDLE_INHERITANCE_WARNING", "1", 1);
1850-
1851-
for (i = 0; i < stdhandles_count; i++) {
1852-
HANDLE h = stdhandles[i];
1853-
strbuf_addf(&buf, "handle #%d: %p (type %lx, "
1854-
"handle info (%d) %lx\n", i, h,
1855-
GetFileType(h),
1856-
GetHandleInformation(h, &fl),
1857-
fl);
1858-
}
1859-
strbuf_addstr(&buf, "\nThis is a bug; please report it "
1860-
"at\nhttps://github.com/git-for-windows/"
1861-
"git/issues/new\n\n"
1862-
"To suppress this warning, please set "
1863-
"the environment variable\n\n"
1864-
"\tSUPPRESS_HANDLE_INHERITANCE_WARNING=1"
1865-
"\n");
1866-
}
1867-
restrict_handle_inheritance = 0;
18681808
flags &= ~EXTENDED_STARTUPINFO_PRESENT;
18691809
ret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL,
18701810
TRUE, flags, wenvblk, dir ? wdir : NULL,

0 commit comments

Comments
 (0)