summaryrefslogtreecommitdiffstats
path: root/Python/getargs.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-07-01 20:34:44 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-07-01 20:34:44 (GMT)
commit3c9ce74c218703ed75a11f71ed215559fa0c4257 (patch)
treed15e279a54aeacd6cf92e27d05b5c4708e699121 /Python/getargs.c
parent3626e5ef2acfa10a5badfa77989c9718faaf790d (diff)
downloadcpython-3c9ce74c218703ed75a11f71ed215559fa0c4257.zip
cpython-3c9ce74c218703ed75a11f71ed215559fa0c4257.tar.gz
cpython-3c9ce74c218703ed75a11f71ed215559fa0c4257.tar.bz2
Issue #23908: os functions, open() and the io.FileIO constructor now reject
unicode paths with embedded null character on Windows instead of silently truncate them.
Diffstat (limited to 'Python/getargs.c')
-rw-r--r--Python/getargs.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index bd15c2e..32ff6fc 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -576,6 +576,17 @@ float_argument_error(PyObject *arg)
return 0;
}
+#ifdef Py_USING_UNICODE
+static size_t
+_ustrlen(Py_UNICODE *u)
+{
+ size_t i = 0;
+ Py_UNICODE *v = u;
+ while (*v != 0) { i++; v++; }
+ return i;
+}
+#endif
+
/* Convert a non-tuple argument. Return NULL if conversion went OK,
or a string with a message describing the failure. The message is
formatted as "must be <desired type>, not <actual type>".
@@ -1202,8 +1213,14 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
format++;
} else {
Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);
- if (PyUnicode_Check(arg))
+ if (PyUnicode_Check(arg)) {
*p = PyUnicode_AS_UNICODE(arg);
+ if (_ustrlen(*p) != (size_t)PyUnicode_GET_SIZE(arg)) {
+ return converterr(
+ "unicode without null characters",
+ arg, msgbuf, bufsize);
+ }
+ }
else
return converterr("unicode", arg, msgbuf, bufsize);
}