summaryrefslogtreecommitdiff
path: root/Lib/test/test_subprocess.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r--Lib/test/test_subprocess.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 9616da03f3..538111564a 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -2216,6 +2216,39 @@ class POSIXProcessTestCase(BaseTestCase):
self.assertNotIn(fd, remaining_fds)
+ @support.cpython_only
+ def test_fork_exec(self):
+ # Issue #22290: fork_exec() must not crash on memory allocation failure
+ # or other errors
+ import _posixsubprocess
+ gc_enabled = gc.isenabled()
+ try:
+ # Use a preexec function and enable the garbage collector
+ # to force fork_exec() to re-enable the garbage collector
+ # on error.
+ func = lambda: None
+ gc.enable()
+
+ executable_list = "exec" # error: must be a sequence
+
+ for args, exe_list, cwd, env_list in (
+ (123, [b"exe"], None, [b"env"]),
+ ([b"arg"], 123, None, [b"env"]),
+ ([b"arg"], [b"exe"], 123, [b"env"]),
+ ([b"arg"], [b"exe"], None, 123),
+ ):
+ with self.assertRaises(TypeError):
+ _posixsubprocess.fork_exec(
+ args, exe_list,
+ True, [], cwd, env_list,
+ -1, -1, -1, -1,
+ 1, 2, 3, 4,
+ True, True, func)
+ finally:
+ if not gc_enabled:
+ gc.disable()
+
+
@unittest.skipUnless(mswindows, "Windows specific tests")
class Win32ProcessTestCase(BaseTestCase):