summaryrefslogtreecommitdiff
path: root/Lib/sqlite3
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-09-27 00:14:24 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2016-09-27 00:14:24 +0300
commit22805ca54e1e5db4b66be1b28b0baac2b1b4b4de (patch)
tree58274b5e8f592ebca990e90533e9137b18989989 /Lib/sqlite3
parentde10dbec778b55edae98aaae095188ef1acd6514 (diff)
parent407ac476905a12e80ef4eb511a2d5111dbe62b99 (diff)
downloadcpython-git-22805ca54e1e5db4b66be1b28b0baac2b1b4b4de.tar.gz
Issue #27897: Fixed possible crash in sqlite3.Connection.create_collation()
if pass invalid string-like object as a name. Patch by Xiang Zhang.
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r--Lib/sqlite3/test/hooks.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/sqlite3/test/hooks.py b/Lib/sqlite3/test/hooks.py
index cafff932b4..f8ef4d88f3 100644
--- a/Lib/sqlite3/test/hooks.py
+++ b/Lib/sqlite3/test/hooks.py
@@ -25,6 +25,11 @@ import unittest
import sqlite3 as sqlite
class CollationTests(unittest.TestCase):
+ def CheckCreateCollationNotString(self):
+ con = sqlite.connect(":memory:")
+ with self.assertRaises(TypeError):
+ con.create_collation(None, lambda x, y: (x > y) - (x < y))
+
def CheckCreateCollationNotCallable(self):
con = sqlite.connect(":memory:")
with self.assertRaises(TypeError) as cm:
@@ -36,6 +41,23 @@ class CollationTests(unittest.TestCase):
with self.assertRaises(sqlite.ProgrammingError):
con.create_collation("collä", lambda x, y: (x > y) - (x < y))
+ def CheckCreateCollationBadUpper(self):
+ class BadUpperStr(str):
+ def upper(self):
+ return None
+ con = sqlite.connect(":memory:")
+ mycoll = lambda x, y: -((x > y) - (x < y))
+ con.create_collation(BadUpperStr("mycoll"), mycoll)
+ result = con.execute("""
+ select x from (
+ select 'a' as x
+ union
+ select 'b' as x
+ ) order by x collate mycoll
+ """).fetchall()
+ self.assertEqual(result[0][0], 'b')
+ self.assertEqual(result[1][0], 'a')
+
@unittest.skipIf(sqlite.sqlite_version_info < (3, 2, 1),
'old SQLite versions crash on this test')
def CheckCollationIsUsed(self):