mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
[security] bpo-13617: Reject embedded null characters in wchar* strings. (#2302)
Based on patch by Victor Stinner. Add private C API function _PyUnicode_AsUnicode() which is similar to PyUnicode_AsUnicode(), but checks for null characters.
This commit is contained in:
parent
592eda1233
commit
f7eae0adfc
22 changed files with 115 additions and 23 deletions
|
@ -4133,6 +4133,20 @@ PyUnicode_AsUnicode(PyObject *unicode)
|
|||
return PyUnicode_AsUnicodeAndSize(unicode, NULL);
|
||||
}
|
||||
|
||||
const Py_UNICODE *
|
||||
_PyUnicode_AsUnicode(PyObject *unicode)
|
||||
{
|
||||
Py_ssize_t size;
|
||||
const Py_UNICODE *wstr;
|
||||
|
||||
wstr = PyUnicode_AsUnicodeAndSize(unicode, &size);
|
||||
if (wstr && wcslen(wstr) != (size_t)size) {
|
||||
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
||||
return NULL;
|
||||
}
|
||||
return wstr;
|
||||
}
|
||||
|
||||
|
||||
Py_ssize_t
|
||||
PyUnicode_GetSize(PyObject *unicode)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue