Skip to content

Commit b0331c9

Browse files
miss-islingtonvstinner
authored andcommitted
bpo-31764: Prevent a crash in sqlite3.Cursor.close() in case the Cursor object is uninitialized (GH-3958) (#4303)
(cherry picked from commit edb13ae)
1 parent 9684cf6 commit b0331c9

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
@@ -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
"""
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 is
2+
uninitialized. Patch by Oren Milman.

Modules/_sqlite/cursor.c

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

917917
PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args)
918918
{
919+
if (!self->connection) {
920+
PyErr_SetString(pysqlite_ProgrammingError,
921+
"Base Cursor.__init__ not called.");
922+
return NULL;
923+
}
919924
if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
920925
return NULL;
921926
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy