diff Objects/unicodeobject.c @ 84283:2f1e8b7fa534 2.7

Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise OverflowError when an argument of %c format is out of range.
author Serhiy Storchaka <storchaka@gmail.com>
date Sun, 23 Jun 2013 20:22:09 +0300
parents 391e3a7db1a3
children 719ee60fc5e2
line wrap: on
line diff
--- a/Objects/unicodeobject.c	Sun Jun 23 16:27:01 2013 +0200
+++ b/Objects/unicodeobject.c	Sun Jun 23 20:22:09 2013 +0300
@@ -740,8 +740,25 @@
 
             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;