]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-105375: Improve posix error handling (GH-105592) (#105598)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 11 Jun 2023 19:33:30 +0000 (12:33 -0700)
committerGitHub <noreply@github.com>
Sun, 11 Jun 2023 19:33:30 +0000 (21:33 +0200)
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>
Misc/NEWS.d/next/Library/2023-06-09-21-30-59.gh-issue-105375.eewafp.rst [new file with mode: 0644]
Modules/posixmodule.c

diff --git a/Misc/NEWS.d/next/Library/2023-06-09-21-30-59.gh-issue-105375.eewafp.rst b/Misc/NEWS.d/next/Library/2023-06-09-21-30-59.gh-issue-105375.eewafp.rst
new file mode 100644 (file)
index 0000000..e000f98
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a bug in the :mod:`posix` module where an exception could be
+overwritten.
index f5e653dd023aefef3a0e223b41edbe9947397bbf..81c9990220893df4f2dfea0f031ee2007bb7c1c5 100644 (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))