Skip to content

Commit c1797f6

Browse files
[3.11] gh-105375: Improve posix error handling (GH-105592) (#105597)
Fix a bug where an IndexError could end up being overwritten. (cherry picked from commit f668f73) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 76682ba commit c1797f6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
Lines changed: 2 additions & 0 deletions
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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5691,7 +5691,7 @@ parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
56915691
{
56925692
Py_ssize_t i, pos, envc;
56935693
PyObject *keys=NULL, *vals=NULL;
5694-
PyObject *key, *val, *key2, *val2, *keyval;
5694+
PyObject *key2, *val2, *keyval;
56955695
EXECV_CHAR **envlist;
56965696

56975697
i = PyMapping_Size(env);
@@ -5716,10 +5716,14 @@ parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
57165716
}
57175717

57185718
for (pos = 0; pos < i; pos++) {
5719-
key = PyList_GetItem(keys, pos);
5720-
val = PyList_GetItem(vals, pos);
5721-
if (!key || !val)
5719+
PyObject *key = PyList_GetItem(keys, pos); // Borrowed ref.
5720+
if (key == NULL) {
57225721
goto error;
5722+
}
5723+
PyObject *val = PyList_GetItem(vals, pos); // Borrowed ref.
5724+
if (val == NULL) {
5725+
goto error;
5726+
}
57235727

57245728
#if defined(HAVE_WEXECV) || defined(HAVE_WSPAWNV)
57255729
if (!PyUnicode_FSDecoder(key, &key2))

0 commit comments

Comments
 (0)