Commit 0b3a87ef authored by Oren Milman's avatar Oren Milman Committed by Serhiy Storchaka

bpo-31471: Fix assertion failure in subprocess.Popen() on Windows, in case env...

bpo-31471: Fix assertion failure in subprocess.Popen() on Windows, in case env has a bad keys() method. (#3580)
parent f350a268
......@@ -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",
......
Fix an assertion failure in `subprocess.Popen()` on Windows, in case the env
argument has a bad keys() method. Patch by Oren Milman.
......@@ -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) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment