summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-12-13 11:15:31 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-12-13 11:15:31 (GMT)
commit507ac3a5910a5404013883ce45ad2f9cf0509b0e (patch)
treece07a2f92b935600c89f39e874f9c704844457b6 /Objects/bytesobject.c
parent590cebe391fb2e199afe9b20ff67e360116a1266 (diff)
parentc9362cf86ae302e89207dff7206b1c6bba413e33 (diff)
downloadcpython-507ac3a5910a5404013883ce45ad2f9cf0509b0e.zip
cpython-507ac3a5910a5404013883ce45ad2f9cf0509b0e.tar.gz
cpython-507ac3a5910a5404013883ce45ad2f9cf0509b0e.tar.bz2
(Merge 3.3) Issue #19969: PyBytes_FromFormatV() now raises an OverflowError if
"%c" argument is not in range [0; 255].
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r--Objects/bytesobject.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 63c67f8..614978b 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -195,8 +195,17 @@ PyBytes_FromFormatV(const char *format, va_list vargs)
switch (*f) {
case 'c':
- (void)va_arg(count, int);
- /* fall through... */
+ {
+ int c = va_arg(count, int);
+ if (c < 0 || c > 255) {
+ PyErr_SetString(PyExc_OverflowError,
+ "PyBytes_FromFormatV(): %c format "
+ "expects an integer in range [0; 255]");
+ return NULL;
+ }
+ n++;
+ break;
+ }
case '%':
n++;
break;
@@ -276,8 +285,12 @@ PyBytes_FromFormatV(const char *format, va_list vargs)
switch (*f) {
case 'c':
- *s++ = va_arg(vargs, int);
+ {
+ int c = va_arg(vargs, int);
+ /* c has been checked for overflow in the first step */
+ *s++ = (unsigned char)c;
break;
+ }
case 'd':
if (longflag)
sprintf(s, "%ld", va_arg(vargs, long));