Mercurial > cpython-lru_cache-weakref
diff Modules/_sqlite/connection.c @ 60845:3f2773ae8448
Issue #8195: Fix a crash in sqlite Connection.create_collation() if the
collation name contains a surrogate character.
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Thu, 22 Apr 2010 11:23:23 +0000 |
| parents | f40a80852480 |
| children | 7ba851d1b46e |
line wrap: on
line diff
--- a/Modules/_sqlite/connection.c Thu Apr 22 10:53:30 2010 +0000 +++ b/Modules/_sqlite/connection.c Thu Apr 22 11:23:23 2010 +0000 @@ -1374,7 +1374,9 @@ 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)) { @@ -1390,19 +1392,24 @@ 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; @@ -1417,7 +1424,7 @@ } 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);
