Skip to content

Commit f21432b

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
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 a990786 commit f21432b

File tree

2 files changed

+4
-70
lines changed

2 files changed

+4
-70
lines changed

Documentation/config/core.adoc

-6
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,6 @@ core.unsetenvvars::
691691
Defaults to `PERL5LIB` to account for the fact that Git for
692692
Windows insists on using its own Perl interpreter.
693693

694-
core.restrictinheritedhandles::
695-
Windows-only: override whether spawned processes inherit only standard
696-
file handles (`stdin`, `stdout` and `stderr`) or all handles. Can be
697-
`auto`, `true` or `false`. Defaults to `auto`, which means `true` on
698-
Windows 7 and later, and `false` on older Windows versions.
699-
700694
core.createObject::
701695
You can set this to 'link', in which case a hardlink followed by
702696
a delete of the source are used to make sure that object creation

compat/mingw.c

+4-64
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ enum hide_dotfiles_type {
241241
HIDE_DOTFILES_DOTGITONLY
242242
};
243243

244-
static int core_restrict_inherited_handles = -1;
245244
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
246245
static char *unset_environment_variables;
247246

@@ -265,15 +264,6 @@ int mingw_core_config(const char *var, const char *value,
265264
return 0;
266265
}
267266

268-
if (!strcmp(var, "core.restrictinheritedhandles")) {
269-
if (value && !strcasecmp(value, "auto"))
270-
core_restrict_inherited_handles = -1;
271-
else
272-
core_restrict_inherited_handles =
273-
git_config_bool(var, value);
274-
return 0;
275-
}
276-
277267
return 0;
278268
}
279269

@@ -1644,7 +1634,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16441634
const char *dir,
16451635
int prepend_cmd, int fhin, int fhout, int fherr)
16461636
{
1647-
static int restrict_handle_inheritance = -1;
16481637
STARTUPINFOEXW si;
16491638
PROCESS_INFORMATION pi;
16501639
LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL;
@@ -1664,16 +1653,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16641653
/* Make sure to override previous errors, if any */
16651654
errno = 0;
16661655

1667-
if (restrict_handle_inheritance < 0)
1668-
restrict_handle_inheritance = core_restrict_inherited_handles;
1669-
/*
1670-
* The following code to restrict which handles are inherited seems
1671-
* to work properly only on Windows 7 and later, so let's disable it
1672-
* on Windows Vista and 2008.
1673-
*/
1674-
if (restrict_handle_inheritance < 0)
1675-
restrict_handle_inheritance = GetVersion() >> 16 >= 7601;
1676-
16771656
do_unset_environment_variables();
16781657

16791658
/* Determine whether or not we are associated to a console */
@@ -1775,7 +1754,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
17751754
wenvblk = make_environment_block(deltaenv);
17761755

17771756
memset(&pi, 0, sizeof(pi));
1778-
if (restrict_handle_inheritance && stdhandles_count &&
1757+
if (stdhandles_count &&
17791758
(InitializeProcThreadAttributeList(NULL, 1, 0, &size) ||
17801759
GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
17811760
(attr_list = (LPPROC_THREAD_ATTRIBUTE_LIST)
@@ -1796,52 +1775,13 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
17961775
&si.StartupInfo, &pi);
17971776

17981777
/*
1799-
* On Windows 2008 R2, it seems that specifying certain types of handles
1800-
* (such as FILE_TYPE_CHAR or FILE_TYPE_PIPE) will always produce an
1801-
* error. Rather than playing finicky and fragile games, let's just try
1802-
* to detect this situation and simply try again without restricting any
1803-
* handle inheritance. This is still better than failing to create
1804-
* processes.
1778+
* On the off-chance that something with the file handle restriction
1779+
* went wrong, silently fall back to trying without it.
18051780
*/
1806-
if (!ret && restrict_handle_inheritance && stdhandles_count) {
1781+
if (!ret && stdhandles_count) {
18071782
DWORD err = GetLastError();
18081783
struct strbuf buf = STRBUF_INIT;
18091784

1810-
if (err != ERROR_NO_SYSTEM_RESOURCES &&
1811-
/*
1812-
* On Windows 7 and earlier, handles on pipes and character
1813-
* devices are inherited automatically, and cannot be
1814-
* specified in the thread handle list. Rather than trying
1815-
* to catch each and every corner case (and running the
1816-
* chance of *still* forgetting a few), let's just fall
1817-
* back to creating the process without trying to limit the
1818-
* handle inheritance.
1819-
*/
1820-
!(err == ERROR_INVALID_PARAMETER &&
1821-
GetVersion() >> 16 < 9200) &&
1822-
!getenv("SUPPRESS_HANDLE_INHERITANCE_WARNING")) {
1823-
DWORD fl = 0;
1824-
int i;
1825-
1826-
setenv("SUPPRESS_HANDLE_INHERITANCE_WARNING", "1", 1);
1827-
1828-
for (i = 0; i < stdhandles_count; i++) {
1829-
HANDLE h = stdhandles[i];
1830-
strbuf_addf(&buf, "handle #%d: %p (type %lx, "
1831-
"handle info (%d) %lx\n", i, h,
1832-
GetFileType(h),
1833-
GetHandleInformation(h, &fl),
1834-
fl);
1835-
}
1836-
strbuf_addstr(&buf, "\nThis is a bug; please report it "
1837-
"at\nhttps://github.com/git-for-windows/"
1838-
"git/issues/new\n\n"
1839-
"To suppress this warning, please set "
1840-
"the environment variable\n\n"
1841-
"\tSUPPRESS_HANDLE_INHERITANCE_WARNING=1"
1842-
"\n");
1843-
}
1844-
restrict_handle_inheritance = 0;
18451785
flags &= ~EXTENDED_STARTUPINFO_PRESENT;
18461786
ret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL,
18471787
TRUE, flags, wenvblk, dir ? wdir : NULL,

0 commit comments

Comments
 (0)