Skip to content

Commit 383af2f

Browse files
committed
Handle PySequence_List() and PyObject_Repr() errors in BaseException_repr()
1 parent 8d17ef3 commit 383af2f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Objects/exceptions.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,10 @@ BaseExceptionGroup_repr(PyObject *op)
11001100
* original exception sequence if possible, for backwards compatibility. */
11011101
if (PyList_Check(PyTuple_GET_ITEM(self->args, 1))) {
11021102
PyObject *exceptions_list = PySequence_List(self->excs);
1103+
if (!exceptions_list) {
1104+
goto error;
1105+
}
1106+
11031107
exceptions_str = PyObject_Repr(exceptions_list);
11041108
Py_DECREF(exceptions_list);
11051109
}
@@ -1108,13 +1112,19 @@ BaseExceptionGroup_repr(PyObject *op)
11081112
}
11091113
}
11101114

1115+
if (!exceptions_str) {
1116+
goto error;
1117+
}
1118+
11111119
const char *name = _PyType_Name(Py_TYPE(self));
11121120
PyObject *repr = PyUnicode_FromFormat(
11131121
"%s(%R, %U)", name,
11141122
self->msg, exceptions_str);
11151123

11161124
Py_DECREF(exceptions_str);
11171125
return repr;
1126+
error:
1127+
return NULL;
11181128
}
11191129

11201130
/*[clinic input]

0 commit comments

Comments
 (0)