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

3 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -190,6 +190,9 @@ def __init__(self, con):

190190

cur = Cursor(con)

191191

with self.assertRaises(sqlite.ProgrammingError):

192192

cur.execute("select 4+5").fetchall()

193+

with self.assertRaisesRegex(sqlite.ProgrammingError,

194+

r'^Base Cursor\.__init__ not called\.$'):

195+

cur.close()

193196
194197

def CheckStrSubclass(self):

195198

"""

Original file line numberDiff line numberDiff 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 numberDiff line numberDiff line change

@@ -889,6 +889,11 @@ PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args)

889889
890890

PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args)

891891

{

892+

if (!self->connection) {

893+

PyErr_SetString(pysqlite_ProgrammingError,

894+

"Base Cursor.__init__ not called.");

895+

return NULL;

896+

}

892897

if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {

893898

return NULL;

894899

}