Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74a7fa6

Browse files
committed
Issue #18408: Fix PyErr_NormalizeException(), handle PyObject_IsSubclass() failure
PyObject_IsSubclass() can fail and raise a new exception!
1 parent bdf630c commit 74a7fa6

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

Python/errors.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,21 @@ PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
227227
value will be an instance.
228228
*/
229229
if (PyExceptionClass_Check(type)) {
230+
int is_subclass;
231+
if (inclass) {
232+
is_subclass = PyObject_IsSubclass(inclass, type);
233+
if (is_subclass < 0)
234+
goto finally;
235+
}
236+
else
237+
is_subclass = 0;
238+
230239
/* if the value was not an instance, or is not an instance
231240
whose class is (or is derived from) type, then use the
232241
value as an argument to instantiation of the type
233242
class.
234243
*/
235-
if (!inclass || !PyObject_IsSubclass(inclass, type)) {
244+
if (!inclass || !is_subclass) {
236245
PyObject *args, *res;
237246

238247
if (value == Py_None)

0 commit comments

Comments
 (0)