commit d2cb3b9e57311c51ddcc47159907da9d2546a1d0 Author: Peter David McCormick Date: Sat Sep 19 12:00:33 2020 -0400 bpo-XXXXX: SQLite: segfault if backup called on closed database diff --git a/Lib/sqlite3/test/backup.py b/Lib/sqlite3/test/backup.py index 2752a4db33..3637c4bb21 100644 --- a/Lib/sqlite3/test/backup.py +++ b/Lib/sqlite3/test/backup.py @@ -35,6 +35,13 @@ class BackupTests(unittest.TestCase): 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)') diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index f765ba1df2..81fc133537 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -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; }