[Python-checkins] cpython: Issue #18519: the Python authorizer callback of sqlite3 must not raise Python

victor.stinner python-checkins at python.org
Fri Jul 26 22:24:01 CEST 2013


http://hg.python.org/cpython/rev/f7a0a4e0ada4
changeset:   84843:f7a0a4e0ada4
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Jul 26 22:23:33 2013 +0200
summary:
  Issue #18519: the Python authorizer callback of sqlite3 must not raise Python exceptions

The exception is printed if sqlite3.enable_callback_tracebacks(True) has been
called, otherwise the exception is cleared.

files:
  Modules/_sqlite/connection.c |  41 +++++++++++------------
  1 files changed, 20 insertions(+), 21 deletions(-)


diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -884,32 +884,31 @@
     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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list