summaryrefslogtreecommitdiffstats
path: root/Lib/sqlite3/test/dbapi.py
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2021-07-29 19:45:32 (GMT)
committerGitHub <noreply@github.com>2021-07-29 19:45:32 (GMT)
commit7e311e496b0e26b3d3c62fe9b0ed2a4677c37ee9 (patch)
tree46ec9f66a8da29a76531818fca182b11b889eb95 /Lib/sqlite3/test/dbapi.py
parent8182c8329c709f42218a8a17d81639ece5b7b627 (diff)
downloadcpython-7e311e496b0e26b3d3c62fe9b0ed2a4677c37ee9.zip
cpython-7e311e496b0e26b3d3c62fe9b0ed2a4677c37ee9.tar.gz
cpython-7e311e496b0e26b3d3c62fe9b0ed2a4677c37ee9.tar.bz2
bpo-31746: Prevent segfaults when sqlite3.Connection is uninitialised (GH-27431)
Diffstat (limited to 'Lib/sqlite3/test/dbapi.py')
-rw-r--r--Lib/sqlite3/test/dbapi.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py
index 20cca33..408f994 100644
--- a/Lib/sqlite3/test/dbapi.py
+++ b/Lib/sqlite3/test/dbapi.py
@@ -243,6 +243,26 @@ class ConnectionTests(unittest.TestCase):
self.assertEqual(cu.fetchone()[0], n)
+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 OpenTests(unittest.TestCase):
_sql = "create table test(id integer)"
@@ -951,6 +971,7 @@ def suite():
ModuleTests,
SqliteOnConflictTests,
ThreadTests,
+ UninitialisedConnectionTests,
]
return unittest.TestSuite(
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]