]> granicus.if.org Git - python/commitdiff
bpo-31764: Prevent a crash in sqlite3.Cursor.close() in case the Cursor object is...
authorOren Milman <orenmn@gmail.com>
Wed, 8 Nov 2017 09:57:02 +0000 (11:57 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 8 Nov 2017 09:57:02 +0000 (01:57 -0800)
Lib/sqlite3/test/regression.py
Misc/NEWS.d/next/Library/2017-11-08-11-02-01.bpo-31764.gtlhKj.rst [new file with mode: 0644]
Modules/_sqlite/cursor.c

index 323b25dbb21af02b5c18570b4bd8b7c30668efb6..7eeac324d272b989a31a1738b3ab25d40852238c 100644 (file)
@@ -177,6 +177,9 @@ class RegressionTests(unittest.TestCase):
             pass
         except:
             self.fail("should have raised ProgrammingError")
+        with self.assertRaisesRegexp(sqlite.ProgrammingError,
+                                     r'^Base Cursor\.__init__ not called\.$'):
+            cur.close()
 
     def CheckConnectionConstructorCallCheck(self):
         """
diff --git a/Misc/NEWS.d/next/Library/2017-11-08-11-02-01.bpo-31764.gtlhKj.rst b/Misc/NEWS.d/next/Library/2017-11-08-11-02-01.bpo-31764.gtlhKj.rst
new file mode 100644 (file)
index 0000000..06af91d
--- /dev/null
@@ -0,0 +1,2 @@
+Prevent a crash in ``sqlite3.Cursor.close()`` in case the ``Cursor`` object
+is uninitialized. Patch by Oren Milman.
index 3197e78aaed633cc19ba65a63ee165fc43deaab8..b7c2d798da5950a807ecff4389d32daec04e2ba3 100644 (file)
@@ -1014,6 +1014,11 @@ PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args)
 
 PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args)
 {
+    if (!self->connection) {
+        PyErr_SetString(pysqlite_ProgrammingError,
+                        "Base Cursor.__init__ not called.");
+        return NULL;
+    }
     if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
         return NULL;
     }