Skip to content

Commit

Permalink
pythongh-105375: Improve posix error handling (python#105592)
Browse files Browse the repository at this point in the history
Fix a bug where an IndexError could end up being overwritten.
  • Loading branch information
erlend-aasland committed Jun 9, 2023
1 parent eede1d2 commit f668f73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
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

0 comments on commit f668f73

Please sign in to comment.