Add private _PyUnicode_AsUTF8NoNUL() function (GH-111957)

Like PyUnicode_AsUTF8(), but check for embedded null characters.
This commit is contained in:
Serhiy Storchaka 2023-11-10 21:31:36 +02:00 committed by GitHub
parent 3932b0f7b1
commit 771bd3c94a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 13 deletions

View file

@ -76,16 +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_AsUTF8NoNUL(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) {
return 0;