diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-06-13 18:21:50 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-06-13 18:21:50 (GMT) |
commit | 06e49dd0297beff7c8462025badfcc561c8c35c8 (patch) | |
tree | d43acb0142df447b8e51eb0e60f68c81f02d09c3 /Python | |
parent | edc5d20f3b3c958caa070750576f64198bc724cb (diff) | |
download | cpython-06e49dd0297beff7c8462025badfcc561c8c35c8.zip cpython-06e49dd0297beff7c8462025badfcc561c8c35c8.tar.gz cpython-06e49dd0297beff7c8462025badfcc561c8c35c8.tar.bz2 |
Issue #8592: PyArg_Parse*() functions raise a TypeError for "y", "u" and "Z"
formats if the string contains a null byte/character. Write unit tests for
string formats.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/getargs.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index 127b147..d4d8d84 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -935,10 +935,15 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, count = convertbuffer(arg, p, &buf); if (count < 0) return converterr(buf, arg, msgbuf, bufsize); - else if (*format == '#') { + if (*format == '#') { FETCH_SIZE; STORE_SIZE(count); format++; + } else { + if (strlen(*p) != count) + return converterr( + "bytes without null bytes", + arg, msgbuf, bufsize); } break; } @@ -1045,9 +1050,13 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, if (arg == Py_None) *p = 0; - else if (PyUnicode_Check(arg)) + else if (PyUnicode_Check(arg)) { *p = PyUnicode_AS_UNICODE(arg); - else + if (Py_UNICODE_strlen(*p) != PyUnicode_GET_SIZE(arg)) + return converterr( + "str without null character or None", + arg, msgbuf, bufsize); + } else return converterr("str or None", arg, msgbuf, bufsize); } break; @@ -1227,6 +1236,11 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, FETCH_SIZE; STORE_SIZE(PyUnicode_GET_SIZE(arg)); format++; + } else { + if (Py_UNICODE_strlen(*p) != PyUnicode_GET_SIZE(arg)) + return converterr( + "str without null character", + arg, msgbuf, bufsize); } break; } |