summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-26 20:23:33 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-07-26 20:23:33 (GMT)
commitd4095d95f87010751ebc0b656a87f422ce5480ad (patch)
tree5c14003b0b03b91f1497fefbab5f5bbd3fe7c1ec /Modules
parent8cda5e60932b5808e6f6af4cfdc1428f1c915555 (diff)
downloadcpython-d4095d95f87010751ebc0b656a87f422ce5480ad.zip
cpython-d4095d95f87010751ebc0b656a87f422ce5480ad.tar.gz
cpython-d4095d95f87010751ebc0b656a87f422ce5480ad.tar.bz2
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.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_sqlite/connection.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 551431c..b56ddac 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -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