Skip to content

Commit ef4bd1b

Browse files
[3.12] gh-110237: Check PyList_Append for errors in _PyEval_MatchClass (GH-110238) (#110511)
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 96e42d2 commit ef4bd1b

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
@@ -489,7 +489,9 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
489489
}
490490
if (match_self) {
491491
// Easy. Copy the subject itself, and move on to kwargs.
492-
PyList_Append(attrs, subject);
492+
if (PyList_Append(attrs, subject) < 0) {
493+
goto fail;
494+
}
493495
}
494496
else {
495497
for (Py_ssize_t i = 0; i < nargs; i++) {
@@ -505,7 +507,10 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
505507
if (attr == NULL) {
506508
goto fail;
507509
}
508-
PyList_Append(attrs, attr);
510+
if (PyList_Append(attrs, attr) < 0) {
511+
Py_DECREF(attr);
512+
goto fail;
513+
}
509514
Py_DECREF(attr);
510515
}
511516
}
@@ -518,7 +523,10 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
518523
if (attr == NULL) {
519524
goto fail;
520525
}
521-
PyList_Append(attrs, attr);
526+
if (PyList_Append(attrs, attr) < 0) {
527+
Py_DECREF(attr);
528+
goto fail;
529+
}
522530
Py_DECREF(attr);
523531
}
524532
Py_SETREF(attrs, PyList_AsTuple(attrs));

0 commit comments

Comments
 (0)