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
gh-105375: Improve posix error handling (GH-105592)
Fix a bug where an IndexError could end up being overwritten.
(cherry picked from commit f668f73)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
  • Loading branch information
erlend-aasland authored and miss-islington committed Jun 9, 2023
commit e607c6b11339c208cf088347e96fb4d0107dcaca
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a bug in the :mod:`posix` module where an exception could be
overwritten.
12 changes: 8 additions & 4 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6414,7 +6414,7 @@ parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
{
Py_ssize_t i, pos, envc;
PyObject *keys=NULL, *vals=NULL;
PyObject *key, *val, *key2, *val2, *keyval;
PyObject *key2, *val2, *keyval;
EXECV_CHAR **envlist;

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

for (pos = 0; pos < i; pos++) {
key = PyList_GetItem(keys, pos);
val = PyList_GetItem(vals, pos);
if (!key || !val)
PyObject *key = PyList_GetItem(keys, pos); // Borrowed ref.
if (key == NULL) {
goto error;
}
PyObject *val = PyList_GetItem(vals, pos); // Borrowed ref.
if (val == NULL) {
goto error;
}

#if defined(HAVE_WEXECV) || defined(HAVE_WSPAWNV)
if (!PyUnicode_FSDecoder(key, &key2))
Expand Down