mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
bpo-41815: SQLite: segfault if backup called on closed database (GH-22322)
GH- [bpo-41815](): SQLite: fix segfault if backup called on closed database
Attempting to backup a closed database will trigger segfault:
```python
import sqlite3
target = sqlite3.connect(':memory:')
source = sqlite3.connect(':memory:')
source.close()
source.backup(target)
```
(cherry picked from commit bfee9fad84
)
Co-authored-by: Peter McCormick <peter@pdmccormick.com>
This commit is contained in:
parent
724df8325d
commit
4ee30c4244
3 changed files with 13 additions and 0 deletions
|
@ -36,6 +36,13 @@ class BackupTests(unittest.TestCase):
|
||||||
with self.assertRaises(sqlite.ProgrammingError):
|
with self.assertRaises(sqlite.ProgrammingError):
|
||||||
self.cx.backup(bck)
|
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):
|
def test_bad_target_in_transaction(self):
|
||||||
bck = sqlite.connect(':memory:')
|
bck = sqlite.connect(':memory:')
|
||||||
bck.execute('CREATE TABLE bar (key INTEGER)')
|
bck.execute('CREATE TABLE bar (key INTEGER)')
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix SQLite3 segfault when backing up closed database. Patch contributed by
|
||||||
|
Peter David McCormick.
|
|
@ -1514,6 +1514,10 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *args, PyObject *
|
||||||
sleep_ms = (int)ms;
|
sleep_ms = (int)ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!pysqlite_check_connection((pysqlite_Connection *)target)) {
|
if (!pysqlite_check_connection((pysqlite_Connection *)target)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue