diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-10-05 15:25:19 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-10-05 15:25:19 (GMT) |
commit | 8f437aac068e13fe8418bb0374baf4395e7b4994 (patch) | |
tree | 498dcc48cfcc4e1472dadb9c1552188db929c3c1 /Lib | |
parent | 340c749a3a091f14c7701b66a05e864c8f95740a (diff) | |
download | cpython-8f437aac068e13fe8418bb0374baf4395e7b4994.zip cpython-8f437aac068e13fe8418bb0374baf4395e7b4994.tar.gz cpython-8f437aac068e13fe8418bb0374baf4395e7b4994.tar.bz2 |
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')
-rw-r--r-- | Lib/test/test_subprocess.py | 33 |
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): |