bpo-31764: Prevent a crash in sqlite3.Cursor.close() in case the Curs… · python/cpython@b0331c9 (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -190,6 +190,9 @@ def __init__(self, con):
190 190 cur = Cursor(con)
191 191 with self.assertRaises(sqlite.ProgrammingError):
192 192 cur.execute("select 4+5").fetchall()
193 +with self.assertRaisesRegex(sqlite.ProgrammingError,
194 +r'^Base Cursor\.__init__ not called\.$'):
195 +cur.close()
193 196
194 197 def CheckStrSubclass(self):
195 198 """
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 +Prevent a crash in ``sqlite3.Cursor.close()`` in case the ``Cursor`` object is
2 +uninitialized. Patch by Oren Milman.
Original file line number Diff line number Diff line change
@@ -916,6 +916,11 @@ PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args)
916 916
917 917 PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args)
918 918 {
919 +if (!self->connection) {
920 +PyErr_SetString(pysqlite_ProgrammingError,
921 +"Base Cursor.__init__ not called.");
922 +return NULL;
923 + }
919 924 if (!pysqlite_check_thread(self->connection) |
920 925 return NULL;
921 926 }