diff Objects/stringobject.c @ 81605:ee93a89b4e0f 2.7

Issue #15989: Fix possible integer overflow in str formatting as in unicode formatting.
author Serhiy Storchaka <storchaka@gmail.com>
date Sat, 19 Jan 2013 23:35:46 +0200
parents ded5386604fd
children 5970c90dd8d1
line wrap: on
line diff
--- a/Objects/stringobject.c	Sat Jan 19 14:58:38 2013 -0500
+++ b/Objects/stringobject.c	Sat Jan 19 23:35:46 2013 +0200
@@ -4355,7 +4355,9 @@
                                     "* wants int");
                     goto error;
                 }
-                width = PyInt_AsLong(v);
+                width = PyInt_AsSsize_t(v);
+                if (width == -1 && PyErr_Occurred())
+                    goto error;
                 if (width < 0) {
                     flags |= F_LJUST;
                     width = -width;
@@ -4392,7 +4394,9 @@
                             "* wants int");
                         goto error;
                     }
-                    prec = PyInt_AsLong(v);
+                    prec = _PyInt_AsInt(v);
+                    if (prec == -1 && PyErr_Occurred())
+                        goto error;
                     if (prec < 0)
                         prec = 0;
                     if (--fmtcnt >= 0)