Skip to content

Commit 6adea57

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 a402e2f commit 6adea57

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
@@ -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

Lines changed: 4 additions & 64 deletions
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

@@ -1647,7 +1637,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16471637
const char *dir,
16481638
int prepend_cmd, int fhin, int fhout, int fherr)
16491639
{
1650-
static int restrict_handle_inheritance = -1;
16511640
STARTUPINFOEXW si;
16521641
PROCESS_INFORMATION pi;
16531642
LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL;
@@ -1667,16 +1656,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16671656
/* Make sure to override previous errors, if any */
16681657
errno = 0;
16691658

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

16821661
/* Determine whether or not we are associated to a console */
@@ -1778,7 +1757,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
17781757
wenvblk = make_environment_block(deltaenv);
17791758

17801759
memset(&pi, 0, sizeof(pi));
1781-
if (restrict_handle_inheritance && stdhandles_count &&
1760+
if (stdhandles_count &&
17821761
(InitializeProcThreadAttributeList(NULL, 1, 0, &size) ||
17831762
GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
17841763
(attr_list = (LPPROC_THREAD_ATTRIBUTE_LIST)
@@ -1799,52 +1778,13 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
17991778
&si.StartupInfo, &pi);
18001779

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

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

0 commit comments

Comments
 (0)