mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.9] bpo-31746: Prevent segfaults when sqlite3.Connection is uninitialised (GH-27431) (GH-27465)
(cherry picked from commit 7e311e496b)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
This commit is contained in:
parent
c2c322b354
commit
0bc17658f5
2 changed files with 45 additions and 8 deletions
|
|
@ -192,6 +192,27 @@ def CheckSameThreadErrorOnOldVersion(self):
|
|||
sqlite.connect(':memory:', check_same_thread=False)
|
||||
self.assertEqual(str(cm.exception), 'shared connections not available')
|
||||
|
||||
|
||||
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:")
|
||||
|
|
@ -943,10 +964,11 @@ def suite():
|
|||
closed_con_suite = unittest.makeSuite(ClosedConTests, "Check")
|
||||
closed_cur_suite = unittest.makeSuite(ClosedCurTests, "Check")
|
||||
on_conflict_suite = unittest.makeSuite(SqliteOnConflictTests, "Check")
|
||||
uninit_con_suite = unittest.makeSuite(UninitialisedConnectionTests)
|
||||
return unittest.TestSuite((
|
||||
module_suite, connection_suite, cursor_suite, thread_suite,
|
||||
constructor_suite, ext_suite, closed_con_suite, closed_cur_suite,
|
||||
on_conflict_suite,
|
||||
on_conflict_suite, uninit_con_suite,
|
||||
))
|
||||
|
||||
def test():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue