Commit a7f1c1d2 authored by Victor Stinner's avatar Victor Stinner

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.
parent 638dde75
...@@ -884,33 +884,32 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co ...@@ -884,33 +884,32 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co
gilstate = PyGILState_Ensure(); gilstate = PyGILState_Ensure();
#endif #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 (ret == NULL) {
if (_enable_callback_tracebacks) { if (_enable_callback_tracebacks)
PyErr_Print(); PyErr_Print();
} else { else
PyErr_Clear(); PyErr_Clear();
}
rc = SQLITE_DENY; rc = SQLITE_DENY;
} else { }
else {
if (PyLong_Check(ret)) { if (PyLong_Check(ret)) {
rc = _PyLong_AsInt(ret); rc = _PyLong_AsInt(ret);
if (rc == -1 && PyErr_Occurred()) if (rc == -1 && PyErr_Occurred()) {
rc = SQLITE_DENY; if (_enable_callback_tracebacks)
} else { PyErr_Print();
else
PyErr_Clear();
rc = SQLITE_DENY; rc = SQLITE_DENY;
} }
Py_DECREF(ret);
}
} }
else { else {
/* A previous call to the authorizer callback failed and raised an
exception: don't call the Python authorizer callback */
rc = SQLITE_DENY; rc = SQLITE_DENY;
} }
Py_DECREF(ret);
}
#ifdef WITH_THREAD #ifdef WITH_THREAD
PyGILState_Release(gilstate); PyGILState_Release(gilstate);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment