]> granicus.if.org Git - python/commitdiff
Issue #18408: Fix PyErr_NormalizeException(), handle PyObject_IsSubclass() failure
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 16 Jul 2013 22:44:53 +0000 (00:44 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 16 Jul 2013 22:44:53 +0000 (00:44 +0200)
PyObject_IsSubclass() can fail and raise a new exception!

Python/errors.c

index 34445b65ea491f8ae10dab5cf3da719068a0c948..53dd9a9650d0c15b5378a5a959fa8e1664672e98 100644 (file)
@@ -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)