bpo-31764: Prevent a crash in sqlite3.Cursor.close() in case the Curs… · python/cpython@edb13ae (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -190,6 +190,9 @@ def __init__(self, con): | ||
190 | 190 | cur = Cursor(con) |
191 | 191 | with self.assertRaises(sqlite.ProgrammingError): |
192 | 192 | cur.execute("select 4+5").fetchall() |
193 | +with self.assertRaisesRegex(sqlite.ProgrammingError, | |
194 | +r'^Base Cursor\.__init__ not called\.$'): | |
195 | +cur.close() | |
193 | 196 | |
194 | 197 | def CheckStrSubclass(self): |
195 | 198 | """ |
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 is | |
2 | +uninitialized. Patch by Oren Milman. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -889,6 +889,11 @@ PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args) | ||
889 | 889 | |
890 | 890 | PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args) |
891 | 891 | { |
892 | +if (!self->connection) { | |
893 | +PyErr_SetString(pysqlite_ProgrammingError, | |
894 | +"Base Cursor.__init__ not called."); | |
895 | +return NULL; | |
896 | + } | |
892 | 897 | if (!pysqlite_check_thread(self->connection) | |
893 | 898 | return NULL; |
894 | 899 | } |