@@ -259,6 +259,7 @@ static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
259
259
static char * unset_environment_variables ;
260
260
int core_fscache ;
261
261
int core_long_paths ;
262
+ int core_restrict_inherited_handles = -1 ;
262
263
263
264
int mingw_core_config (const char * var , const char * value , void * cb )
264
265
{
@@ -286,6 +287,15 @@ int mingw_core_config(const char *var, const char *value, void *cb)
286
287
return 0 ;
287
288
}
288
289
290
+ if (!strcmp (var , "core.restrictinheritedhandles" )) {
291
+ if (value && !strcasecmp (value , "auto" ))
292
+ core_restrict_inherited_handles = -1 ;
293
+ else
294
+ core_restrict_inherited_handles =
295
+ git_config_bool (var , value );
296
+ return 0 ;
297
+ }
298
+
289
299
return 0 ;
290
300
}
291
301
@@ -1674,7 +1684,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1674
1684
const char * dir , const char * prepend_cmd ,
1675
1685
int fhin , int fhout , int fherr )
1676
1686
{
1677
- static int restrict_handle_inheritance = 1 ;
1687
+ static int restrict_handle_inheritance = - 1 ;
1678
1688
STARTUPINFOEXW si ;
1679
1689
PROCESS_INFORMATION pi ;
1680
1690
LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL ;
@@ -1690,6 +1700,16 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1690
1700
is_msys2_sh (* argv ) ? quote_arg_msys2 : quote_arg_msvc ;
1691
1701
const char * strace_env ;
1692
1702
1703
+ if (restrict_handle_inheritance < 0 )
1704
+ restrict_handle_inheritance = core_restrict_inherited_handles ;
1705
+ /*
1706
+ * The following code to restrict which handles are inherited seems
1707
+ * to work properly only on Windows 7 and later, so let's disable it
1708
+ * on Windows Vista and 2008.
1709
+ */
1710
+ if (restrict_handle_inheritance < 0 )
1711
+ restrict_handle_inheritance = GetVersion () >> 16 >= 7601 ;
1712
+
1693
1713
do_unset_environment_variables ();
1694
1714
1695
1715
/* Determine whether or not we are associated to a console */
0 commit comments