summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-06-28 07:31:00 (GMT)
committerGitHub <noreply@github.com>2017-06-28 07:31:00 (GMT)
commit54ba940abc2fabb94fede46dfad80f8ac15632a3 (patch)
tree6c5d594ac7e15a9b50a04a8f674e2362602ab9de /Objects
parent9dff523e42a5f8eca8e88151785be54468e57969 (diff)
downloadcpython-54ba940abc2fabb94fede46dfad80f8ac15632a3.zip
cpython-54ba940abc2fabb94fede46dfad80f8ac15632a3.tar.gz
cpython-54ba940abc2fabb94fede46dfad80f8ac15632a3.tar.bz2
[3.5] bpo-13617: Reject embedded null characters in wchar* strings. (GH-2302) (#2463)
Based on patch by Victor Stinner. Add private C API function _PyUnicode_AsUnicode() which is similar to PyUnicode_AsUnicode(), but checks for null characters.. (cherry picked from commit f7eae0adfcd4c50034281b2c69f461b43b68db84)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 64375da..66cb4af 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -3894,6 +3894,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)