diff options
author | Oren Milman <orenmn@gmail.com> | 2017-09-14 19:30:28 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-14 19:30:27 (GMT) |
commit | 0b3a87ef54a0112b74e8a1d8c6f87d10db4239ab (patch) | |
tree | 626fd137e6154d665e7b0fe8e17360ad78d2ef84 | |
parent | f350a268a7071ce7d7a5bb86a9b1229782d4963b (diff) | |
download | cpython-0b3a87ef54a0112b74e8a1d8c6f87d10db4239ab.zip cpython-0b3a87ef54a0112b74e8a1d8c6f87d10db4239ab.tar.gz cpython-0b3a87ef54a0112b74e8a1d8c6f87d10db4239ab.tar.bz2 |
bpo-31471: Fix assertion failure in subprocess.Popen() on Windows, in case env has a bad keys() method. (#3580)
-rw-r--r-- | Lib/test/test_subprocess.py | 9 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2017-09-14-19-47-57.bpo-31471.0yiA5Q.rst | 2 | ||||
-rw-r--r-- | Modules/_winapi.c | 6 |
3 files changed, 16 insertions, 1 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 10ef87b..00dc37b 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -2742,6 +2742,15 @@ class Win32ProcessTestCase(BaseTestCase): stdout=subprocess.PIPE, close_fds=True) + @support.cpython_only + def test_issue31471(self): + # There shouldn't be an assertion failure in Popen() in case the env + # argument has a bad keys() method. + class BadEnv(dict): + keys = None + with self.assertRaises(TypeError): + subprocess.Popen([sys.executable, "-c", "pass"], env=BadEnv()) + def test_close_fds(self): # close file descriptors rc = subprocess.call([sys.executable, "-c", diff --git a/Misc/NEWS.d/next/Core and Builtins/2017-09-14-19-47-57.bpo-31471.0yiA5Q.rst b/Misc/NEWS.d/next/Core and Builtins/2017-09-14-19-47-57.bpo-31471.0yiA5Q.rst new file mode 100644 index 0000000..73c4444 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2017-09-14-19-47-57.bpo-31471.0yiA5Q.rst @@ -0,0 +1,2 @@ +Fix an assertion failure in `subprocess.Popen()` on Windows, in case the env +argument has a bad keys() method. Patch by Oren Milman. diff --git a/Modules/_winapi.c b/Modules/_winapi.c index a81ccaf..00a26d51 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -723,9 +723,13 @@ getenvironment(PyObject* environment) } keys = PyMapping_Keys(environment); + if (!keys) { + return NULL; + } values = PyMapping_Values(environment); - if (!keys || !values) + if (!values) { goto error; + } envsize = PySequence_Fast_GET_SIZE(keys); if (PySequence_Fast_GET_SIZE(values) != envsize) { |