summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_subprocess.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-10-05 15:25:48 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-10-05 15:25:48 (GMT)
commitf4e4b83824318c2415e1d90d00726d07ba8790b9 (patch)
treeb54757b863c64ddb45c6b6bd75850230b81891e9 /Lib/test/test_subprocess.py
parent31e34fe7a3a4545d3efb4f11ceaf269012585689 (diff)
parent8f437aac068e13fe8418bb0374baf4395e7b4994 (diff)
downloadcpython-f4e4b83824318c2415e1d90d00726d07ba8790b9.zip
cpython-f4e4b83824318c2415e1d90d00726d07ba8790b9.tar.gz
cpython-f4e4b83824318c2415e1d90d00726d07ba8790b9.tar.bz2
(Merge 3.4) Issue #22290: Fix error handling in the _posixsubprocess module.
* Don't call the garbage collector with an exception set: it causes an assertion to fail in debug mode. * Enhance also error handling if allocating an array for the executable list failed. * Add an unit test for 4 different errors in the _posixsubprocess module.
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 9616da0..5381115 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):