Skip to content

Commit f21c09c

Browse files
[3.11] gh-110237: Check PyList_Append for errors in _PyEval_MatchClass (GH-110238) (#110512)
gh-110237: Check `PyList_Append` for errors in `_PyEval_MatchClass` (GH-110238) (cherry picked from commit dd9d781) Co-authored-by: denballakh <[email protected]>
1 parent af168df commit f21c09c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix missing error checks for calls to ``PyList_Append`` in ``_PyEval_MatchClass``.

Python/ceval.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,9 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
10601060
}
10611061
if (match_self) {
10621062
// Easy. Copy the subject itself, and move on to kwargs.
1063-
PyList_Append(attrs, subject);
1063+
if (PyList_Append(attrs, subject) < 0) {
1064+
goto fail;
1065+
}
10641066
}
10651067
else {
10661068
for (Py_ssize_t i = 0; i < nargs; i++) {
@@ -1076,7 +1078,10 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
10761078
if (attr == NULL) {
10771079
goto fail;
10781080
}
1079-
PyList_Append(attrs, attr);
1081+
if (PyList_Append(attrs, attr) < 0) {
1082+
Py_DECREF(attr);
1083+
goto fail;
1084+
}
10801085
Py_DECREF(attr);
10811086
}
10821087
}
@@ -1089,7 +1094,10 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
10891094
if (attr == NULL) {
10901095
goto fail;
10911096
}
1092-
PyList_Append(attrs, attr);
1097+
if (PyList_Append(attrs, attr) < 0) {
1098+
Py_DECREF(attr);
1099+
goto fail;
1100+
}
10931101
Py_DECREF(attr);
10941102
}
10951103
Py_SETREF(attrs, PyList_AsTuple(attrs));

0 commit comments

Comments
 (0)