]> 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>
Tue, 7 Nov 2017 00:09:49 +0000 (02:09 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 7 Nov 2017 00:09:49 +0000 (16:09 -0800)
Lib/sqlite3/test/regression.py
Misc/NEWS.d/next/Library/2017-10-11-22-18-04.bpo-31764.EMyIkK.rst [new file with mode: 0644]
Modules/_sqlite/cursor.c

index 3ff9abd98993f7865191f6f23d2e03025bfee0da..34cd233535dc16488fcf509a16333436dc12a6de 100644 (file)
@@ -190,6 +190,9 @@ class RegressionTests(unittest.TestCase):
         cur = Cursor(con)
         with self.assertRaises(sqlite.ProgrammingError):
             cur.execute("select 4+5").fetchall()
+        with self.assertRaisesRegex(sqlite.ProgrammingError,
+                                    r'^Base Cursor\.__init__ not called\.$'):
+            cur.close()
 
     def CheckStrSubclass(self):
         """
diff --git a/Misc/NEWS.d/next/Library/2017-10-11-22-18-04.bpo-31764.EMyIkK.rst b/Misc/NEWS.d/next/Library/2017-10-11-22-18-04.bpo-31764.EMyIkK.rst
new file mode 100644 (file)
index 0000000..a5a4ce5
--- /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 f7a34c10c2ac925ec1c66e102eae4a91b97c2085..4ecb5b4b92c6310643a7043831a8d44a608a7a59 100644 (file)
@@ -889,6 +889,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;
     }