8000 bpo-31764: Prevent a crash in sqlite3.Cursor.close() in case the Curs… · python/cpython@cd66d6d · GitHub
[go: up one dir, main page]

Skip to content

Commit cd66d6d

Browse files
orenmnvstinner
authored andcommitted
bpo-31764: Prevent a crash in sqlite3.Cursor.close() in case the Cursor object is uninitialized (GH-4333)
1 parent 47eaaa5 commit cd66d6d

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Lib/sqlite3/test/regression.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ def __init__(self, con):
177177
pass
178178
except:
179179
self.fail("should have raised ProgrammingError")
180+
with self.assertRaisesRegexp(sqlite.ProgrammingError,
181+
r'^Base Cursor\.__init__ not called\.$'):
182+
cur.close()
180183

181184
def CheckConnectionConstructorCallCheck(self):
182185
"""
Lines changed: 2 additions & 0 deletions
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
2+
is uninitialized. Patch by Oren Milman.

Modules/_sqlite/cursor.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,11 @@ PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args)
10141014

10151015
PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args)
10161016
{
1017+
if (!self->connection) {
1018+
PyErr_SetString(pysqlite_ProgrammingError,
1019+
"Base Cursor.__init__ not called.");
1020+
return NULL;
1021+
}
10171022
if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
10181023
return NULL;
10191024
}

0 commit comments

Comments
 (0)
0