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

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