]> granicus.if.org Git - python/commitdiff
Issue #18519: the Python authorizer callback of sqlite3 must not raise Python exceptions
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 26 Jul 2013 20:23:33 +0000 (22:23 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 26 Jul 2013 20:23:33 +0000 (22:23 +0200)
The exception is printed if sqlite3.enable_callback_tracebacks(True) has been
called, otherwise the exception is cleared.

Modules/_sqlite/connection.c

index 551431c0dbf8c5171ebf39326e4fa1c348148fab..b56ddac136ea6c4c65e608f9cffc1bb33e03f685 100644 (file)
@@ -884,32 +884,31 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co
     gilstate = PyGILState_Ensure();
 #endif
 
-    if (!PyErr_Occurred()) {
-        ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source);
+    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 == NULL) {
+        if (_enable_callback_tracebacks)
+            PyErr_Print();
+        else
+            PyErr_Clear();
 
-            rc = SQLITE_DENY;
-        } else {
-            if (PyLong_Check(ret)) {
-                rc = _PyLong_AsInt(ret);
-                if (rc == -1 && PyErr_Occurred())
-                    rc = SQLITE_DENY;
-            } else {
+        rc = SQLITE_DENY;
+    }
+    else {
+        if (PyLong_Check(ret)) {
+            rc = _PyLong_AsInt(ret);
+            if (rc == -1 && PyErr_Occurred()) {
+                if (_enable_callback_tracebacks)
+                    PyErr_Print();
+                else
+                    PyErr_Clear();
                 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 {
+            rc = SQLITE_DENY;
+        }
+        Py_DECREF(ret);
     }
 
 #ifdef WITH_THREAD