summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-06-11 19:33:30 (GMT)
committerGitHub <noreply@github.com>2023-06-11 19:33:30 (GMT)
commitc14f6ea7e44790d0518c3a0c17b8b1336f3a1602 (patch)
tree9947d5bbe689c40040d896210c2156e8b7eb7f67 /Modules/posixmodule.c
parent071d559def83f0bc51e87a0ca83d45cf4bd6662b (diff)
downloadcpython-c14f6ea7e44790d0518c3a0c17b8b1336f3a1602.zip
cpython-c14f6ea7e44790d0518c3a0c17b8b1336f3a1602.tar.gz
cpython-c14f6ea7e44790d0518c3a0c17b8b1336f3a1602.tar.bz2
[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 f668f73bc88cce0112b304d87aa998fb28013c71) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index f5e653d..81c9990 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))