@@ -259,6 +259,7 @@ static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
259259static char * unset_environment_variables ;
260260int core_fscache ;
261261int core_long_paths ;
262+ int core_restrict_inherited_handles = -1 ;
262263
263264int mingw_core_config (const char * var , const char * value , void * cb )
264265{
@@ -286,6 +287,15 @@ int mingw_core_config(const char *var, const char *value, void *cb)
286287 return 0 ;
287288 }
288289
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+
289299 return 0 ;
290300}
291301
@@ -1674,7 +1684,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16741684 const char * dir , const char * prepend_cmd ,
16751685 int fhin , int fhout , int fherr )
16761686{
1677- static int restrict_handle_inheritance = 1 ;
1687+ static int restrict_handle_inheritance = - 1 ;
16781688 STARTUPINFOEXW si ;
16791689 PROCESS_INFORMATION pi ;
16801690 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
16901700 is_msys2_sh (* argv ) ? quote_arg_msys2 : quote_arg_msvc ;
16911701 const char * strace_env ;
16921702
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+
16931713 do_unset_environment_variables ();
16941714
16951715 /* Determine whether or not we are associated to a console */
0 commit comments