diff options
-rw-r--r-- | Lib/sqlite3/test/backup.py | 7 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2020-09-19-23-14-54.bpo-41815.RNpuX3.rst | 2 | ||||
-rw-r--r-- | Modules/_sqlite/connection.c | 4 |
3 files changed, 13 insertions, 0 deletions
diff --git a/Lib/sqlite3/test/backup.py b/Lib/sqlite3/test/backup.py index 2752a4d..3637c4b 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/Misc/NEWS.d/next/Library/2020-09-19-23-14-54.bpo-41815.RNpuX3.rst b/Misc/NEWS.d/next/Library/2020-09-19-23-14-54.bpo-41815.RNpuX3.rst new file mode 100644 index 0000000..3560db9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-09-19-23-14-54.bpo-41815.RNpuX3.rst @@ -0,0 +1,2 @@ +Fix SQLite3 segfault when backing up closed database. Patch contributed by +Peter David McCormick. diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index f765ba1..81fc133 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; } |