Kaydet (Commit) d4095d95 authored tarafından 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.
üst 8cda5e60
...@@ -884,32 +884,31 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co ...@@ -884,32 +884,31 @@ 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 { }
if (PyLong_Check(ret)) { else {
rc = _PyLong_AsInt(ret); if (PyLong_Check(ret)) {
if (rc == -1 && PyErr_Occurred()) rc = _PyLong_AsInt(ret);
rc = SQLITE_DENY; if (rc == -1 && PyErr_Occurred()) {
} else { if (_enable_callback_tracebacks)
PyErr_Print();
else
PyErr_Clear();
rc = SQLITE_DENY; rc = SQLITE_DENY;
} }
Py_DECREF(ret);
} }
} else {
else { rc = SQLITE_DENY;
/* A previous call to the authorizer callback failed and raised an }
exception: don't call the Python authorizer callback */ Py_DECREF(ret);
rc = SQLITE_DENY;
} }
#ifdef WITH_THREAD #ifdef WITH_THREAD
......
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