Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/sqlite3/test/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def test_bad_target_closed_connection(self):
with self.assertRaises(sqlite.ProgrammingError):
self.cx.backup(bck)

def test_bad_source_closed_connection(self):
bck = sqlite.connect(':memory:')
source = sqlite.connect(":memory:")
source.close()
with self.assertRaises(sqlite.ProgrammingError):
source.backup(bck)

def test_bad_target_in_transaction(self):
bck = sqlite.connect(':memory:')
bck.execute('CREATE TABLE bar (key INTEGER)')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix SQLite3 segfault when backing up closed database. Patch contributed by
Peter David McCormick.
4 changes: 4 additions & 0 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,10 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *args, PyObject *
sleep_ms = (int)ms;
}

if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
}

if (!pysqlite_check_connection((pysqlite_Connection *)target)) {
return NULL;
}
Expand Down