Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2742,6 +2742,15 @@ def test_invalid_args(self):
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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 5 additions & 1 deletion Modules/_winapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down