diff Modules/_sqlite/connection.c @ 84760:026593cbc006

Issue #18519, #18408: Fix sqlite authorizer callback If a previous call to the authorizer callback failed and raised an exception, don't call the Python authorizer callback, but just return SQLITE_DENY.
author Victor Stinner <victor.stinner@gmail.com>
date Sun, 21 Jul 2013 13:05:38 +0200
parents a2214ab0812e
children 020dbfdf9517
line wrap: on
line diff
--- a/Modules/_sqlite/connection.c	Sun Jul 21 01:51:07 2013 -0700
+++ b/Modules/_sqlite/connection.c	Sun Jul 21 13:05:38 2013 +0200
@@ -883,25 +883,33 @@
 
     gilstate = PyGILState_Ensure();
 #endif
-    ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source);
+
+    if (!PyErr_Occurred()) {
+        ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source);
+
+        if (!ret) {
+            if (_enable_callback_tracebacks) {
+                PyErr_Print();
+            } else {
+                PyErr_Clear();
+            }
 
-    if (!ret) {
-        if (_enable_callback_tracebacks) {
-            PyErr_Print();
+            rc = SQLITE_DENY;
         } else {
-            PyErr_Clear();
+            if (PyLong_Check(ret)) {
+                rc = _PyLong_AsInt(ret);
+                if (rc == -1 && PyErr_Occurred())
+                    rc = SQLITE_DENY;
+            } else {
+                rc = SQLITE_DENY;
+            }
+            Py_DECREF(ret);
         }
-
+    }
+    else {
+        /* A previous call to the authorizer callback failed and raised an
+           exception: don't call the Python authorizer callback */
         rc = SQLITE_DENY;
-    } else {
-        if (PyLong_Check(ret)) {
-            rc = _PyLong_AsInt(ret);
-            if (rc == -1 && PyErr_Occurred())
-                rc = SQLITE_DENY;
-        } else {
-            rc = SQLITE_DENY;
-        }
-        Py_DECREF(ret);
     }
 
 #ifdef WITH_THREAD