Mercurial > cpython-lru_cache-weakref
diff Python/getargs.c @ 62322:b32a2816f6e9
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.
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sun, 13 Jun 2010 18:21:50 +0000 |
| parents | fe5ed70283ef |
| children | 0840a283af5f |
line wrap: on
line diff
--- a/Python/getargs.c Sun Jun 13 12:02:07 2010 +0000 +++ b/Python/getargs.c Sun Jun 13 18:21:50 2010 +0000 @@ -935,10 +935,15 @@ 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 @@ 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 @@ 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; }
