[3.12] gh-105375: Improve posix error handling (GH-105592) (#105598)

Fix a bug where an IndexError could end up being overwritten.
(cherry picked from commit f668f73bc8)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
Miss Islington (bot) 2023-06-11 12:33:30 -07:00 committed by GitHub
parent 071d559def
commit c14f6ea7e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -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);
@ -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))