Commit cd66d6d6 authored by Oren Milman's avatar Oren Milman Committed by Victor Stinner

bpo-31764: Prevent a crash in sqlite3.Cursor.close() in case the Cursor object...

bpo-31764: Prevent a crash in sqlite3.Cursor.close() in case the Cursor object is uninitialized (GH-4333)
parent 47eaaa55
...@@ -177,6 +177,9 @@ class RegressionTests(unittest.TestCase): ...@@ -177,6 +177,9 @@ class RegressionTests(unittest.TestCase):
pass pass
except: except:
self.fail("should have raised ProgrammingError") self.fail("should have raised ProgrammingError")
with self.assertRaisesRegexp(sqlite.ProgrammingError,
r'^Base Cursor\.__init__ not called\.$'):
cur.close()
def CheckConnectionConstructorCallCheck(self): def CheckConnectionConstructorCallCheck(self):
""" """
......
Prevent a crash in ``sqlite3.Cursor.close()`` in case the ``Cursor`` object
is uninitialized. Patch by Oren Milman.
...@@ -1014,6 +1014,11 @@ PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args) ...@@ -1014,6 +1014,11 @@ PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args)
PyObject* pysqlite_cursor_close(pysqlite_Cursor* 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)) { if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment