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

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -177,6 +177,9 @@ def __init__(self, con):
177 177 pass
178 178 except:
179 179 self.fail("should have raised ProgrammingError")
180 +with self.assertRaisesRegexp(sqlite.ProgrammingError,
181 +r'^Base Cursor\.__init__ not called\.$'):
182 +cur.close()
180 183
181 184 def CheckConnectionConstructorCallCheck(self):
182 185 """
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
2 +is uninitialized. Patch by Oren Milman.
Original file line number Diff line number Diff line change
@@ -1014,6 +1014,11 @@ PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args)
1014 1014
1015 1015 PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args)
1016 1016 {
1017 +if (!self->connection) {
1018 +PyErr_SetString(pysqlite_ProgrammingError,
1019 +"Base Cursor.__init__ not called.");
1020 +return NULL;
1021 + }
1017 1022 if (!pysqlite_check_thread(self->connection) |
1018 1023 return NULL;
1019 1024 }