@@ -2312,8 +2312,6 @@ def test_fork_exec(self):
23122312 func = lambda : None
23132313 gc .enable ()
23142314
2315- executable_list = "exec" # error: must be a sequence
2316-
23172315 for args , exe_list , cwd , env_list in (
23182316 (123 , [b"exe" ], None , [b"env" ]),
23192317 ([b"arg" ], 123 , None , [b"env" ]),
@@ -2331,6 +2329,34 @@ def test_fork_exec(self):
23312329 if not gc_enabled :
23322330 gc .disable ()
23332331
2332+ @support .cpython_only
2333+ def test_fork_exec_sorted_fd_sanity_check (self ):
2334+ # Issue #23564: sanity check the fork_exec() fds_to_keep sanity check.
2335+ import _posixsubprocess
2336+ gc_enabled = gc .isenabled ()
2337+ try :
2338+ gc .enable ()
2339+
2340+ for fds_to_keep in (
2341+ (- 1 , 2 , 3 , 4 , 5 ), # Negative number.
2342+ ('str' , 4 ), # Not an int.
2343+ (18 , 23 , 42 , 2 ** 63 ), # Out of range.
2344+ (5 , 4 ), # Not sorted.
2345+ (6 , 7 , 7 , 8 ), # Duplicate.
2346+ ):
2347+ with self .assertRaises (
2348+ ValueError ,
2349+ msg = 'fds_to_keep={}' .format (fds_to_keep )) as c :
2350+ _posixsubprocess .fork_exec (
2351+ [b"false" ], [b"false" ],
2352+ True , fds_to_keep , None , [b"env" ],
2353+ - 1 , - 1 , - 1 , - 1 ,
2354+ 1 , 2 , 3 , 4 ,
2355+ True , True , None )
2356+ self .assertIn ('fds_to_keep' , str (c .exception ))
2357+ finally :
2358+ if not gc_enabled :
2359+ gc .disable ()
23342360
23352361
23362362@unittest .skipUnless (mswindows , "Windows specific tests" )
0 commit comments