diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-03 17:53:46 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-03 17:53:46 (GMT) |
commit | 41525e31a5a40c1c20a5115aed9609f49c60b43a (patch) | |
tree | 45340b82cb8c98bb088b5b3227a3e5b9e6464603 /Objects | |
parent | 45ec3288d0e181334efcaeac7ce6ef44771a2689 (diff) | |
download | cpython-41525e31a5a40c1c20a5115aed9609f49c60b43a.zip cpython-41525e31a5a40c1c20a5115aed9609f49c60b43a.tar.gz cpython-41525e31a5a40c1c20a5115aed9609f49c60b43a.tar.bz2 |
Issue #23466: Raised OverflowError if %c argument is out of range.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/bytesobject.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 5a2d41c..27d6472 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -496,10 +496,15 @@ byte_converter(PyObject *arg, char *p) ival = PyLong_AsLongAndOverflow(iobj, &overflow); Py_DECREF(iobj); } - if (!overflow && 0 <= ival && ival <= 255) { - *p = (char)ival; - return 1; + if (!overflow && ival == -1 && PyErr_Occurred()) + goto onError; + if (overflow || !(0 <= ival && ival <= 255)) { + PyErr_SetString(PyExc_OverflowError, + "%c arg not in range(256)"); + return 0; } + *p = (char)ival; + return 1; } onError: PyErr_SetString(PyExc_TypeError, |