mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
gh-127208: Reject null character in _imp.create_dynamic() (#127400)
_imp.create_dynamic() now rejects embedded null characters in the
path and in the module name.
Backport also the _PyUnicode_AsUTF8NoNUL() function.
(cherry picked from commit b14fdadc6c
)
This commit is contained in:
parent
fc0564b365
commit
e7ab97862d
4 changed files with 33 additions and 3 deletions
|
@ -3991,6 +3991,18 @@ PyUnicode_AsUTF8(PyObject *unicode)
|
|||
return PyUnicode_AsUTF8AndSize(unicode, NULL);
|
||||
}
|
||||
|
||||
const char *
|
||||
_PyUnicode_AsUTF8NoNUL(PyObject *unicode)
|
||||
{
|
||||
Py_ssize_t size;
|
||||
const char *s = PyUnicode_AsUTF8AndSize(unicode, &size);
|
||||
if (s && strlen(s) != (size_t)size) {
|
||||
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
||||
return NULL;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
PyUnicode_GetSize() has been deprecated since Python 3.3
|
||||
because it returned length of Py_UNICODE.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue