From 41525e31a5a40c1c20a5115aed9609f49c60b43a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 3 Apr 2015 20:53:46 +0300 Subject: Issue #23466: Raised OverflowError if %c argument is out of range. --- Objects/bytesobject.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Objects/bytesobject.c') diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 5a2d41c5a8..27d6472292 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, -- cgit v1.2.1