Skip to content

Commit dd9d781

Browse files
authored
gh-110237: Check PyList_Append for errors in _PyEval_MatchClass (#110238)
1 parent de2a403 commit dd9d781

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
@@ -506,7 +506,9 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
506506
}
507507
if (match_self) {
508508
// Easy. Copy the subject itself, and move on to kwargs.
509-
PyList_Append(attrs, subject);
509+
if (PyList_Append(attrs, subject) < 0) {
510+
goto fail;
511+
}
510512
}
511513
else {
512514
for (Py_ssize_t i = 0; i < nargs; i++) {
@@ -522,7 +524,10 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
522524
if (attr == NULL) {
523525
goto fail;
524526
}
525-
PyList_Append(attrs, attr);
527+
if (PyList_Append(attrs, attr) < 0) {
528+
Py_DECREF(attr);
529+
goto fail;
530+
}
526531
Py_DECREF(attr);
527532
}
528533
}
@@ -535,7 +540,10 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
535540
if (attr == NULL) {
536541
goto fail;
537542
}
538-
PyList_Append(attrs, attr);
543+
if (PyList_Append(attrs, attr) < 0) {
544+
Py_DECREF(attr);
545+
goto fail;
546+
}
539547
Py_DECREF(attr);
540548
}
541549
Py_SETREF(attrs, PyList_AsTuple(attrs));

0 commit comments

Comments
 (0)