]> granicus.if.org Git - python/commitdiff
Merged revisions 80349 via svnmerge from
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 22 Apr 2010 11:24:50 +0000 (11:24 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 22 Apr 2010 11:24:50 +0000 (11:24 +0000)
svn+ssh://pythondev@svn.python.org/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.
........

Lib/sqlite3/test/regression.py
Misc/NEWS
Modules/_sqlite/connection.c

index da445519d9664ede6705df0f6efe9b47005b453e..5e315fa0fb650b54a0c073fea35e31f826c52e66 100644 (file)
@@ -183,6 +183,13 @@ class RegressionTests(unittest.TestCase):
         """
         self.assertRaises(sqlite.Warning, self.con, 1)
 
+    def CheckCollation(self):
+        def collation_cb(a, b):
+            return 1
+        self.assertRaises(sqlite.ProgrammingError, self.con.create_collation,
+            # Lone surrogate cannot be encoded to the default encoding (utf8)
+            "\uDC80", collation_cb)
+
 def suite():
     regression_suite = unittest.makeSuite(RegressionTests, "Check")
     return unittest.TestSuite((regression_suite,))
index c9f1bcc761e47ccb1334143ebd63b5fbaf80b9a0..6b3177480634c162b3d2a70f24a5b6a455958373 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -33,6 +33,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #8195: Fix a crash in sqlite Connection.create_collation() if the
+  collation name contains a surrogate character.
+
 - Issue #8484: Load all ciphers and digest algorithms when initializing
   the _ssl extension, such that verification of some SSL certificates
   doesn't fail because of an "unknown algorithm".
index 4b8088d0f5e6aa91f2f672b893eb70de73e87d37..11fb4ac864828acfb9001303553af97498ebdf3e 100644 (file)
@@ -1228,7 +1228,9 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
     PyObject* uppercase_name = 0;
     PyObject* name;
     PyObject* retval;
-    char* chk;
+    Py_UNICODE* chk;
+    Py_ssize_t i, len;
+    char *uppercase_name_str;
     int rc;
 
     if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
@@ -1244,19 +1246,24 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
         goto finally;
     }
 
-    chk = _PyUnicode_AsString(uppercase_name);
-    while (*chk) {
+    len = PyUnicode_GET_SIZE(uppercase_name);
+    chk = PyUnicode_AS_UNICODE(uppercase_name);
+    for (i=0; i<len; i++, chk++) {
         if ((*chk >= '0' && *chk <= '9')
          || (*chk >= 'A' && *chk <= 'Z')
          || (*chk == '_'))
         {
-            chk++;
+            continue;
         } else {
             PyErr_SetString(pysqlite_ProgrammingError, "invalid character in collation name");
             goto finally;
         }
     }
 
+    uppercase_name_str = _PyUnicode_AsString(uppercase_name);
+    if (!uppercase_name_str)
+        goto finally;
+
     if (callable != Py_None && !PyCallable_Check(callable)) {
         PyErr_SetString(PyExc_TypeError, "parameter must be callable");
         goto finally;
@@ -1269,7 +1276,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
     }
 
     rc = sqlite3_create_collation(self->db,
-                                  _PyUnicode_AsString(uppercase_name),
+                                  uppercase_name_str,
                                   SQLITE_UTF8,
                                   (callable != Py_None) ? callable : NULL,
                                   (callable != Py_None) ? pysqlite_collation_callback : NULL);