From: Victor Stinner Date: Tue, 16 Jul 2013 22:44:53 +0000 (+0200) Subject: Issue #18408: Fix PyErr_NormalizeException(), handle PyObject_IsSubclass() failure X-Git-Tag: v3.4.0a1~177 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=74a7fa66639bf7960916e2862140dd2546d3c0c8;p=python Issue #18408: Fix PyErr_NormalizeException(), handle PyObject_IsSubclass() failure PyObject_IsSubclass() can fail and raise a new exception! --- diff --git a/Python/errors.c b/Python/errors.c index 34445b65ea..53dd9a9650 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -227,12 +227,21 @@ PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb) value will be an instance. */ if (PyExceptionClass_Check(type)) { + int is_subclass; + if (inclass) { + is_subclass = PyObject_IsSubclass(inclass, type); + if (is_subclass < 0) + goto finally; + } + else + is_subclass = 0; + /* if the value was not an instance, or is not an instance whose class is (or is derived from) type, then use the value as an argument to instantiation of the type class. */ - if (!inclass || !PyObject_IsSubclass(inclass, type)) { + if (!inclass || !is_subclass) { PyObject *args, *res; if (value == Py_None)