Blame SOURCES/00212-pep466-pyunicode_fromformat-raise-overflow.patch

925e6b
925e6b
# HG changeset patch
925e6b
# User Serhiy Storchaka <storchaka@gmail.com>
925e6b
# Date 1372008129 -10800
925e6b
# Node ID 2f1e8b7fa534b147280fdc9b92e44a7c7305338a
925e6b
# Parent  8f0adcb66633ee97e4f7bdeee2104268113b86c3
925e6b
Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise
925e6b
OverflowError when an argument of %c format is out of range.
925e6b
925e6b
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
925e6b
--- a/Objects/unicodeobject.c
925e6b
+++ b/Objects/unicodeobject.c
925e6b
@@ -740,8 +740,25 @@ PyUnicode_FromFormatV(const char *format
925e6b
 
925e6b
             switch (*f) {
925e6b
             case 'c':
925e6b
-                (void)va_arg(count, int);
925e6b
+            {
925e6b
+                int ordinal = va_arg(count, int);
925e6b
+#ifdef Py_UNICODE_WIDE
925e6b
+                if (ordinal < 0 || ordinal > 0x10ffff) {
925e6b
+                    PyErr_SetString(PyExc_OverflowError,
925e6b
+                                    "%c arg not in range(0x110000) "
925e6b
+                                    "(wide Python build)");
925e6b
+                    goto fail;
925e6b
+                }
925e6b
+#else
925e6b
+                if (ordinal < 0 || ordinal > 0xffff) {
925e6b
+                    PyErr_SetString(PyExc_OverflowError,
925e6b
+                                    "%c arg not in range(0x10000) "
925e6b
+                                    "(narrow Python build)");
925e6b
+                    goto fail;
925e6b
+                }
925e6b
+#endif
925e6b
                 /* fall through... */
925e6b
+            }
925e6b
             case '%':
925e6b
                 n++;
925e6b
                 break;
925e6b