]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 23 Jun 2013 17:22:09 +0000 (20:22 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 23 Jun 2013 17:22:09 +0000 (20:22 +0300)
OverflowError when an argument of %c format is out of range.

Misc/NEWS
Objects/unicodeobject.c

index d7e15f3878023526cdad4af863ae79ad1220d462..09d252a1174a98b5d3f3f181e360c061bcb6cad9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@ What's New in Python 2.7.6?
 Core and Builtins
 -----------------
 
+- Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise
+  OverflowError when an argument of %c format is out of range.
+
 - Issue #18137: Detect integer overflow on precision in float.__format__()
   and complex.__format__().
 
index 0ead06f242cd79f271476e1f5ec24009f2478ea0..64a5ef557c05754d17fe1863c6251ce172d1c2ed 100644 (file)
@@ -740,8 +740,25 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
 
             switch (*f) {
             case 'c':
-                (void)va_arg(count, int);
+            {
+                int ordinal = va_arg(count, int);
+#ifdef Py_UNICODE_WIDE
+                if (ordinal < 0 || ordinal > 0x10ffff) {
+                    PyErr_SetString(PyExc_OverflowError,
+                                    "%c arg not in range(0x110000) "
+                                    "(wide Python build)");
+                    goto fail;
+                }
+#else
+                if (ordinal < 0 || ordinal > 0xffff) {
+                    PyErr_SetString(PyExc_OverflowError,
+                                    "%c arg not in range(0x10000) "
+                                    "(narrow Python build)");
+                    goto fail;
+                }
+#endif
                 /* fall through... */
+            }
             case '%':
                 n++;
                 break;