Mercurial > cpython-lru_cache-weakref
diff Objects/stringobject.c @ 52409:6e591d4dc6c9 2.6
Merged revisions 70682 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70682 | mark.dickinson | 2009-03-29 17:17:16 +0100 (Sun, 29 Mar 2009) | 3 lines
Issue #532631: Add paranoid check to avoid potential buffer overflow
on systems with sizeof(int) > 4.
........
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sun, 29 Mar 2009 16:18:33 +0000 |
| parents | 423c9477d6ef |
| children | bfb2337451e9 |
line wrap: on
line diff
--- a/Objects/stringobject.c Sun Mar 29 15:06:29 2009 +0000 +++ b/Objects/stringobject.c Sun Mar 29 16:18:33 2009 +0000 @@ -4336,6 +4336,15 @@ } if (prec < 0) prec = 6; + /* make sure that the decimal representation of precision really does + need at most 10 digits: platforms with sizeof(int) == 8 exist! */ + if (prec > 0x7fffffffL) { + PyErr_SetString(PyExc_OverflowError, + "outrageously large precision " + "for formatted float"); + return -1; + } + if (type == 'f' && fabs(x) >= 1e50) type = 'g'; /* Worst case length calc to ensure no buffer overrun: @@ -4364,7 +4373,7 @@ PyOS_snprintf(fmt, sizeof(fmt), "%%%s.%d%c", (flags&F_ALT) ? "#" : "", prec, type); - PyOS_ascii_formatd(buf, buflen, fmt, x); + PyOS_ascii_formatd(buf, buflen, fmt, x); return (int)strlen(buf); }
