summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-06-28 08:30:06 +0300
committerGitHub <noreply@github.com>2017-06-28 08:30:06 +0300
commitf7eae0adfcd4c50034281b2c69f461b43b68db84 (patch)
tree02d6a582fd81f615e71c55365f1b37a774fc0a4e /Objects/unicodeobject.c
parentbpo-24813: IDLE tagline is Integrated Development and Learning Environment (... (diff)
downloadcpython-f7eae0adfcd4c50034281b2c69f461b43b68db84.tar.gz
cpython-f7eae0adfcd4c50034281b2c69f461b43b68db84.tar.bz2
cpython-f7eae0adfcd4c50034281b2c69f461b43b68db84.zip
[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/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 646de0e917a..e396d68d120 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)