gh-111089: Use PyUnicode_AsUTF8() in sqlite3 (#111122)

PyUnicode_AsUTF8() now raises an exception if the string contains
embedded null characters.
This commit is contained in:
Victor Stinner 2023-10-20 20:04:27 +02:00 committed by GitHub
parent ea7c26e4b8
commit 37e4e20eaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 6 deletions

View File

@ -76,15 +76,10 @@ isolation_level_converter(PyObject *str_or_none, const char **result)
*result = NULL; *result = NULL;
} }
else if (PyUnicode_Check(str_or_none)) { else if (PyUnicode_Check(str_or_none)) {
Py_ssize_t sz; const char *str = PyUnicode_AsUTF8(str_or_none);
const char *str = PyUnicode_AsUTF8AndSize(str_or_none, &sz);
if (str == NULL) { if (str == NULL) {
return 0; return 0;
} }
if (strlen(str) != (size_t)sz) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
return 0;
}
const char *level = get_isolation_level(str); const char *level = get_isolation_level(str);
if (level == NULL) { if (level == NULL) {