]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-110237: Check `PyList_Append` for errors in `_PyEval_MatchClass` (GH-110238...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 8 Oct 2023 00:40:38 +0000 (17:40 -0700)
committerGitHub <noreply@github.com>
Sun, 8 Oct 2023 00:40:38 +0000 (00:40 +0000)
gh-110237: Check `PyList_Append` for errors in `_PyEval_MatchClass` (GH-110238)
(cherry picked from commit dd9d781da30aa3740e54c063a40413c542d78c25)

Co-authored-by: denballakh <47365157+denballakh@users.noreply.github.com>
Misc/NEWS.d/next/Core and Builtins/2023-10-02-23-17-08.gh-issue-110237._Xub0z.rst [new file with mode: 0644]
Python/ceval.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-10-02-23-17-08.gh-issue-110237._Xub0z.rst b/Misc/NEWS.d/next/Core and Builtins/2023-10-02-23-17-08.gh-issue-110237._Xub0z.rst
new file mode 100644 (file)
index 0000000..67b95c5
--- /dev/null
@@ -0,0 +1 @@
+Fix missing error checks for calls to ``PyList_Append`` in ``_PyEval_MatchClass``.
index fdb5b72e6c0f7b3bb34d9d779e0eedc167683f58..4845ec04f08cc7458262c7a0041006974f852350 100644 (file)
@@ -489,7 +489,9 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
         }
         if (match_self) {
             // Easy. Copy the subject itself, and move on to kwargs.
-            PyList_Append(attrs, subject);
+            if (PyList_Append(attrs, subject) < 0) {
+                goto fail;
+            }
         }
         else {
             for (Py_ssize_t i = 0; i < nargs; i++) {
@@ -505,7 +507,10 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
                 if (attr == NULL) {
                     goto fail;
                 }
-                PyList_Append(attrs, attr);
+                if (PyList_Append(attrs, attr) < 0) {
+                    Py_DECREF(attr);
+                    goto fail;
+                }
                 Py_DECREF(attr);
             }
         }
@@ -518,7 +523,10 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
         if (attr == NULL) {
             goto fail;
         }
-        PyList_Append(attrs, attr);
+        if (PyList_Append(attrs, attr) < 0) {
+            Py_DECREF(attr);
+            goto fail;
+        }
         Py_DECREF(attr);
     }
     Py_SETREF(attrs, PyList_AsTuple(attrs));