]> granicus.if.org Git - python/commitdiff
Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
authorGerhard Häring <gh@ghaering.de>
Fri, 5 Mar 2010 15:50:25 +0000 (15:50 +0000)
committerGerhard Häring <gh@ghaering.de>
Fri, 5 Mar 2010 15:50:25 +0000 (15:50 +0000)
Lib/sqlite3/test/dbapi.py
Misc/NEWS
Modules/_sqlite/connection.c

index e774f744e4ba9aea1e9ec188a5398c16279cbf72..29a04d76d48a46b1b4f6c650e908a1ce72495961 100644 (file)
@@ -763,6 +763,73 @@ class ClosedTests(unittest.TestCase):
         except:
             self.fail("Should have raised a ProgrammingError")
 
+
+    def CheckClosedCreateFunction(self):
+        con = sqlite.connect(":memory:")
+        con.close()
+        def f(x): return 17
+        try:
+            con.create_function("foo", 1, f)
+            self.fail("Should have raised a ProgrammingError")
+        except sqlite.ProgrammingError:
+            pass
+        except:
+            self.fail("Should have raised a ProgrammingError")
+
+    def CheckClosedCreateAggregate(self):
+        con = sqlite.connect(":memory:")
+        con.close()
+        class Agg:
+            def __init__(self):
+                pass
+            def step(self, x):
+                pass
+            def finalize(self):
+                return 17
+        try:
+            con.create_aggregate("foo", 1, Agg)
+            self.fail("Should have raised a ProgrammingError")
+        except sqlite.ProgrammingError:
+            pass
+        except:
+            self.fail("Should have raised a ProgrammingError")
+
+    def CheckClosedSetAuthorizer(self):
+        con = sqlite.connect(":memory:")
+        con.close()
+        def authorizer(*args):
+            return sqlite.DENY
+        try:
+            con.set_authorizer(authorizer)
+            self.fail("Should have raised a ProgrammingError")
+        except sqlite.ProgrammingError:
+            pass
+        except:
+            self.fail("Should have raised a ProgrammingError")
+
+    def CheckClosedSetProgressCallback(self):
+        con = sqlite.connect(":memory:")
+        con.close()
+        def progress(): pass
+        try:
+            con.set_progress_handler(progress, 100)
+            self.fail("Should have raised a ProgrammingError")
+        except sqlite.ProgrammingError:
+            pass
+        except:
+            self.fail("Should have raised a ProgrammingError")
+
+    def CheckClosedCall(self):
+        con = sqlite.connect(":memory:")
+        con.close()
+        try:
+            con()
+            self.fail("Should have raised a ProgrammingError")
+        except sqlite.ProgrammingError:
+            pass
+        except:
+            self.fail("Should have raised a ProgrammingError")
+
 def suite():
     module_suite = unittest.makeSuite(ModuleTests, "Check")
     connection_suite = unittest.makeSuite(ConnectionTests, "Check")
index 558abfc4ca6237aa4e8600fd04f3474ba079f7c7..f46438f32aba2bd7a2fabad6f508f4d9be372ef7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,10 @@ Core and Builtins
 Library
 -------
 
+Extension Modules
+-----------------
+
+- Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
 
 What's New in Python 2.6.5 rc 1?
 ================================
index 74177910baa8464a4d59211a88ca9bffdce98590..309b16852cd082ee799cac9fa376c8d310abdc22 100644 (file)
@@ -765,6 +765,10 @@ PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObjec
     int narg;
     int rc;
 
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
+        return NULL;
+    }
+
     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO", kwlist,
                                      &name, &narg, &func))
     {
@@ -794,6 +798,10 @@ PyObject* pysqlite_connection_create_aggregate(pysqlite_Connection* self, PyObje
     static char *kwlist[] = { "name", "n_arg", "aggregate_class", NULL };
     int rc;
 
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
+        return NULL;
+    }
+
     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO:create_aggregate",
                                       kwlist, &name, &n_arg, &aggregate_class)) {
         return NULL;
@@ -884,6 +892,10 @@ PyObject* pysqlite_connection_set_authorizer(pysqlite_Connection* self, PyObject
     static char *kwlist[] = { "authorizer_callback", NULL };
     int rc;
 
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
+        return NULL;
+    }
+
     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:set_authorizer",
                                       kwlist, &authorizer_cb)) {
         return NULL;
@@ -909,6 +921,10 @@ PyObject* pysqlite_connection_set_progress_handler(pysqlite_Connection* self, Py
 
     static char *kwlist[] = { "progress_handler", "n", NULL };
 
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
+        return NULL;
+    }
+
     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi:set_progress_handler",
                                       kwlist, &progress_handler, &n)) {
         return NULL;
@@ -1020,6 +1036,10 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py
     PyObject* weakref;
     int rc;
 
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
+        return NULL;
+    }
+
     if (!PyArg_ParseTuple(args, "O", &sql)) {
         return NULL;
     }