From 37e4e20eaa8f27ada926d49e5971fecf0477ad26 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 20 Oct 2023 20:04:27 +0200 Subject: [PATCH] gh-111089: Use PyUnicode_AsUTF8() in sqlite3 (#111122) PyUnicode_AsUTF8() now raises an exception if the string contains embedded null characters. --- Modules/_sqlite/connection.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 319ed0c29c7a9b..ce46c1e69f3131 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -76,15 +76,10 @@ isolation_level_converter(PyObject *str_or_none, const char **result) *result = NULL; } else if (PyUnicode_Check(str_or_none)) { - Py_ssize_t sz; - const char *str = PyUnicode_AsUTF8AndSize(str_or_none, &sz); + const char *str = PyUnicode_AsUTF8(str_or_none); if (str == NULL) { return 0; } - if (strlen(str) != (size_t)sz) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - return 0; - } const char *level = get_isolation_level(str); if (level == NULL) {