Skip to content

Commit f668f73

Browse files
gh-105375: Improve posix error handling (#105592)
Fix a bug where an IndexError could end up being overwritten.
1 parent eede1d2 commit f668f73

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a bug in the :mod:`posix` module where an exception could be
2+
overwritten.

Modules/posixmodule.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -6414,7 +6414,7 @@ parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
64146414
{
64156415
Py_ssize_t i, pos, envc;
64166416
PyObject *keys=NULL, *vals=NULL;
6417-
PyObject *key, *val, *key2, *val2, *keyval;
6417+
PyObject *key2, *val2, *keyval;
64186418
EXECV_CHAR **envlist;
64196419

64206420
i = PyMapping_Size(env);
@@ -6439,10 +6439,14 @@ parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
64396439
}
64406440

64416441
for (pos = 0; pos < i; pos++) {
6442-
key = PyList_GetItem(keys, pos);
6443-
val = PyList_GetItem(vals, pos);
6444-
if (!key || !val)
6442+
PyObject *key = PyList_GetItem(keys, pos); // Borrowed ref.
6443+
if (key == NULL) {
64456444
goto error;
6445+
}
6446+
PyObject *val = PyList_GetItem(vals, pos); // Borrowed ref.
6447+
if (val == NULL) {
6448+
goto error;
6449+
}
64466450

64476451
#if defined(HAVE_WEXECV) || defined(HAVE_WSPAWNV)
64486452
if (!PyUnicode_FSDecoder(key, &key2))

0 commit comments

Comments
 (0)