[Python-checkins] r78700 - in python/branches/release31-maint: Lib/sqlite3/test/dbapi.py Misc/NEWS Modules/_sqlite/connection.c

gerhard.haering python-checkins at python.org
Fri Mar 5 16:55:56 CET 2010


Author: gerhard.haering
Date: Fri Mar  5 16:55:55 2010
New Revision: 78700

Log:
Issue #7670: sqlite3: Fixed crashes when operating on closed connections.


Modified:
   python/branches/release31-maint/Lib/sqlite3/test/dbapi.py
   python/branches/release31-maint/Misc/NEWS
   python/branches/release31-maint/Modules/_sqlite/connection.c

Modified: python/branches/release31-maint/Lib/sqlite3/test/dbapi.py
==============================================================================
--- python/branches/release31-maint/Lib/sqlite3/test/dbapi.py	(original)
+++ python/branches/release31-maint/Lib/sqlite3/test/dbapi.py	Fri Mar  5 16:55:55 2010
@@ -744,6 +744,73 @@
         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")

Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS	(original)
+++ python/branches/release31-maint/Misc/NEWS	Fri Mar  5 16:55:55 2010
@@ -356,6 +356,8 @@
 Extension Modules
 -----------------
 
+- Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
+
 - Stop providing crtassem.h symbols when compiling with Visual Studio 2010, as
   msvcr100.dll is not a platform assembly anymore.
 

Modified: python/branches/release31-maint/Modules/_sqlite/connection.c
==============================================================================
--- python/branches/release31-maint/Modules/_sqlite/connection.c	(original)
+++ python/branches/release31-maint/Modules/_sqlite/connection.c	Fri Mar  5 16:55:55 2010
@@ -690,6 +690,10 @@
     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))
     {
@@ -719,6 +723,10 @@
     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;
@@ -809,6 +817,10 @@
     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;
@@ -834,6 +846,10 @@
 
     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;
@@ -948,6 +964,10 @@
     PyObject* weakref;
     int rc;
 
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
+        return NULL;
+    }
+
     if (!PyArg_ParseTuple(args, "O", &sql)) {
         return NULL;
     }


More information about the Python-checkins mailing list