From cb1f74ec405b81dd1319b616829dd576a48603f8 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 19 Dec 2013 16:38:03 +0100 Subject: Issue #20026: Fix the sqlite module to handle correctly invalid isolation level (wrong type). --- Lib/sqlite3/test/regression.py | 5 +++++ Misc/NEWS | 3 +++ Modules/_sqlite/connection.c | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index b927cb3..c557ab6 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -330,6 +330,11 @@ class RegressionTests(unittest.TestCase): datetime.datetime(2012, 4, 4, 15, 6, 0, 123456), ]) + def CheckInvalidIsolationLevelType(self): + # isolation level is a string, not an integer + self.assertRaises(TypeError, + sqlite.connect, ":memory:", isolation_level=123) + def suite(): regression_suite = unittest.makeSuite(RegressionTests, "Check") diff --git a/Misc/NEWS b/Misc/NEWS index 554f295..dec9424 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -29,6 +29,9 @@ Core and Builtins Library ------- +- Issue #20026: Fix the sqlite module to handle correctly invalid isolation + level (wrong type). + - Issue #18829: csv.Dialect() now checks type for delimiter, escapechar and quotechar fields. Original patch by Vajrasky Kok. diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 451ea24..8cf2d6a 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -109,7 +109,10 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject Py_INCREF(isolation_level); } self->isolation_level = NULL; - pysqlite_connection_set_isolation_level(self, isolation_level); + if (pysqlite_connection_set_isolation_level(self, isolation_level) < 0) { + Py_DECREF(isolation_level); + return -1; + } Py_DECREF(isolation_level); self->statement_cache = (pysqlite_Cache*)PyObject_CallFunction((PyObject*)&pysqlite_CacheType, "Oi", self, cached_statements); -- cgit v0.12