diff options
author | Erlend E. Aasland <erlend.aasland@protonmail.com> | 2023-06-09 20:07:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-09 20:07:47 (GMT) |
commit | f668f73bc88cce0112b304d87aa998fb28013c71 (patch) | |
tree | 7435f4969737c214ca0ecdf6c098d64029c8d440 /Modules/posixmodule.c | |
parent | eede1d2f48b4fe7f7918952d9ebeb744b58668c1 (diff) | |
download | cpython-f668f73bc88cce0112b304d87aa998fb28013c71.zip cpython-f668f73bc88cce0112b304d87aa998fb28013c71.tar.gz cpython-f668f73bc88cce0112b304d87aa998fb28013c71.tar.bz2 |
gh-105375: Improve posix error handling (#105592)
Fix a bug where an IndexError could end up being overwritten.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 6f01b70..694cff1 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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)) |