summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/sqlite3/test/regression.py3
-rw-r--r--Misc/NEWS.d/next/Library/2017-10-11-22-18-04.bpo-31764.EMyIkK.rst2
-rw-r--r--Modules/_sqlite/cursor.c5
3 files changed, 10 insertions, 0 deletions
diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py
index 3ff9abd..34cd233 100644
--- a/Lib/sqlite3/test/regression.py
+++ b/Lib/sqlite3/test/regression.py
@@ -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
index 0000000..a5a4ce5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-10-11-22-18-04.bpo-31764.EMyIkK.rst
@@ -0,0 +1,2 @@
+Prevent a crash in ``sqlite3.Cursor.close()`` in case the ``Cursor`` object is
+uninitialized. Patch by Oren Milman.
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index f7a34c1..4ecb5b4 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -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;
}