mirror of
https://github.com/python/cpython.git
synced 2025-10-08 08:01:55 +00:00
gh-111089: PyUnicode_AsUTF8() now raises on embedded NUL (#111091)
* PyUnicode_AsUTF8() now raises an exception if the string contains embedded null characters. * Update related C API tests (test_capi.test_unicode). * type_new_set_doc() uses PyUnicode_AsUTF8AndSize() to silently truncate doc containing null bytes. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
59ea0f523e
commit
d731579bfb
8 changed files with 49 additions and 25 deletions
|
@ -3837,7 +3837,13 @@ PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize)
|
|||
const char *
|
||||
PyUnicode_AsUTF8(PyObject *unicode)
|
||||
{
|
||||
return PyUnicode_AsUTF8AndSize(unicode, NULL);
|
||||
Py_ssize_t size;
|
||||
const char *utf8 = PyUnicode_AsUTF8AndSize(unicode, &size);
|
||||
if (utf8 != NULL && strlen(utf8) != (size_t)size) {
|
||||
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
||||
return NULL;
|
||||
}
|
||||
return utf8;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue