Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d4095d9

Browse files
committed
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.
1 parent 8cda5e6 commit d4095d9

1 file changed

Lines changed: 20 additions & 21 deletions

File tree

Modules/_sqlite/connection.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -884,32 +884,31 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co
884884
gilstate = PyGILState_Ensure();
885885
#endif
886886

887-
if (!PyErr_Occurred()) {
888-
ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source);
887+
ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source);
889888

890-
if (!ret) {
891-
if (_enable_callback_tracebacks) {
892-
PyErr_Print();
893-
} else {
894-
PyErr_Clear();
895-
}
889+
if (ret == NULL) {
890+
if (_enable_callback_tracebacks)
891+
PyErr_Print();
892+
else
893+
PyErr_Clear();
896894

897-
rc = SQLITE_DENY;
898-
} else {
899-
if (PyLong_Check(ret)) {
900-
rc = _PyLong_AsInt(ret);
901-
if (rc == -1 && PyErr_Occurred())
902-
rc = SQLITE_DENY;
903-
} else {
895+
rc = SQLITE_DENY;
896+
}
897+
else {
898+
if (PyLong_Check(ret)) {
899+
rc = _PyLong_AsInt(ret);
900+
if (rc == -1 && PyErr_Occurred()) {
901+
if (_enable_callback_tracebacks)
902+
PyErr_Print();
903+
else
904+
PyErr_Clear();
904905
rc = SQLITE_DENY;
905906
}
906-
Py_DECREF(ret);
907907
}
908-
}
909-
else {
910-
/* A previous call to the authorizer callback failed and raised an
911-
exception: don't call the Python authorizer callback */
912-
rc = SQLITE_DENY;
908+
else {
909+
rc = SQLITE_DENY;
910+
}
911+
Py_DECREF(ret);
913912
}
914913

915914
#ifdef WITH_THREAD

0 commit comments

Comments
 (0)