diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-06-28 05:30:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-28 05:30:06 (GMT) |
commit | f7eae0adfcd4c50034281b2c69f461b43b68db84 (patch) | |
tree | 02d6a582fd81f615e71c55365f1b37a774fc0a4e /Objects | |
parent | 592eda123329bb5ce2bffcbe3701be6b909f1b2a (diff) | |
download | cpython-f7eae0adfcd4c50034281b2c69f461b43b68db84.zip cpython-f7eae0adfcd4c50034281b2c69f461b43b68db84.tar.gz cpython-f7eae0adfcd4c50034281b2c69f461b43b68db84.tar.bz2 |
[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.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 646de0e..e396d68 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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) |