summaryrefslogtreecommitdiff
path: root/Modules/_cursesmodule.c
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 /Modules/_cursesmodule.c
parent592eda123329bb5ce2bffcbe3701be6b909f1b2a (diff)
downloadcpython-git-f7eae0adfcd4c50034281b2c69f461b43b68db84.tar.gz
[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 'Modules/_cursesmodule.c')
-rw-r--r--Modules/_cursesmodule.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index 5dc0865c1c..a70915143c 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -341,9 +341,11 @@ static int
PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj,
PyObject **bytes, wchar_t **wstr)
{
+ char *str;
if (PyUnicode_Check(obj)) {
#ifdef HAVE_NCURSESW
assert (wstr != NULL);
+
*wstr = PyUnicode_AsWideCharString(obj, NULL);
if (*wstr == NULL)
return 0;
@@ -353,12 +355,20 @@ PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj,
*bytes = PyUnicode_AsEncodedString(obj, win->encoding, NULL);
if (*bytes == NULL)
return 0;
+ /* check for embedded null bytes */
+ if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) {
+ return 0;
+ }
return 1;
#endif
}
else if (PyBytes_Check(obj)) {
Py_INCREF(obj);
*bytes = obj;
+ /* check for embedded null bytes */
+ if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) {
+ return 0;
+ }
return 1;
}