mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.10] bpo-31746: Prevent segfaults when sqlite3.Connection is uninitialised (GH-27431). (GH-27472)
(cherry picked from commit 7e311e496b)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
This commit is contained in:
parent
472997659b
commit
0cb470e622
2 changed files with 43 additions and 7 deletions
|
|
@ -197,6 +197,26 @@ def test_open_uri(self):
|
|||
cx.execute('insert into test(id) values(1)')
|
||||
|
||||
|
||||
class UninitialisedConnectionTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.cx = sqlite.Connection.__new__(sqlite.Connection)
|
||||
|
||||
def test_uninit_operations(self):
|
||||
funcs = (
|
||||
lambda: self.cx.isolation_level,
|
||||
lambda: self.cx.total_changes,
|
||||
lambda: self.cx.in_transaction,
|
||||
lambda: self.cx.iterdump(),
|
||||
lambda: self.cx.cursor(),
|
||||
lambda: self.cx.close(),
|
||||
)
|
||||
for func in funcs:
|
||||
with self.subTest(func=func):
|
||||
self.assertRaisesRegex(sqlite.ProgrammingError,
|
||||
"Base Connection.__init__ not called",
|
||||
func)
|
||||
|
||||
|
||||
class CursorTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.cx = sqlite.connect(":memory:")
|
||||
|
|
@ -949,6 +969,7 @@ def suite():
|
|||
ModuleTests,
|
||||
SqliteOnConflictTests,
|
||||
ThreadTests,
|
||||
UninitialisedConnectionTests,
|
||||
]
|
||||
return unittest.TestSuite(
|
||||
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue