Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b05700

Browse files
author
Victor Stinner
committed
Merged revisions 80349 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r80349 | victor.stinner | 2010-04-22 13:23:23 +0200 (jeu., 22 avril 2010) | 3 lines Issue #8195: Fix a crash in sqlite Connection.create_collation() if the collation name contains a surrogate character. ........
1 parent d0ab48f commit 9b05700

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

Lib/sqlite3/test/regression.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ def CheckConnectionCall(self):
183183
"""
184184
self.assertRaises(sqlite.Warning, self.con, 1)
185185

186+
def CheckCollation(self):
187+
def collation_cb(a, b):
188+
return 1
189+
self.assertRaises(sqlite.ProgrammingError, self.con.create_collation,
190+
# Lone surrogate cannot be encoded to the default encoding (utf8)
191+
"\uDC80", collation_cb)
192+
186193
def suite():
187194
regression_suite = unittest.makeSuite(RegressionTests, "Check")
188195
return unittest.TestSuite((regression_suite,))

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Core and Builtins
3333
Library
3434
-------
3535

36+
- Issue #8195: Fix a crash in sqlite Connection.create_collation() if the
37+
collation name contains a surrogate character.
38+
3639
- Issue #8484: Load all ciphers and digest algorithms when initializing
3740
the _ssl extension, such that verification of some SSL certificates
3841
doesn't fail because of an "unknown algorithm".

Modules/_sqlite/connection.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,9 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
12281228
PyObject* uppercase_name = 0;
12291229
PyObject* name;
12301230
PyObject* retval;
1231-
char* chk;
1231+
Py_UNICODE* chk;
1232+
Py_ssize_t i, len;
1233+
char *uppercase_name_str;
12321234
int rc;
12331235

12341236
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
@@ -1244,19 +1246,24 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
12441246
goto finally;
12451247
}
12461248

1247-
chk = _PyUnicode_AsString(uppercase_name);
1248-
while (*chk) {
1249+
len = PyUnicode_GET_SIZE(uppercase_name);
1250+
chk = PyUnicode_AS_UNICODE(uppercase_name);
1251+
for (i=0; i<len; i++, chk++) {
12491252
if ((*chk >= '0' && *chk <= '9')
12501253
|| (*chk >= 'A' && *chk <= 'Z')
12511254
|| (*chk == '_'))
12521255
{
1253-
chk++;
1256+
continue;
12541257
} else {
12551258
PyErr_SetString(pysqlite_ProgrammingError, "invalid character in collation name");
12561259
goto finally;
12571260
}
12581261
}
12591262

1263+
uppercase_name_str = _PyUnicode_AsString(uppercase_name);
1264+
if (!uppercase_name_str)
1265+
goto finally;
1266+
12601267
if (callable != Py_None && !PyCallable_Check(callable)) {
12611268
PyErr_SetString(PyExc_TypeError, "parameter must be callable");
12621269
goto finally;
@@ -1269,7 +1276,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
12691276
}
12701277

12711278
rc = sqlite3_create_collation(self->db,
1272-
_PyUnicode_AsString(uppercase_name),
1279+
uppercase_name_str,
12731280
SQLITE_UTF8,
12741281
(callable != Py_None) ? callable : NULL,
12751282
(callable != Py_None) ? pysqlite_collation_callback : NULL);

0 commit comments

Comments
 (0)