summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Baxter <anthonybaxter@gmail.com>2006-10-23 15:23:22 (GMT)
committerAnthony Baxter <anthonybaxter@gmail.com>2006-10-23 15:23:22 (GMT)
commit1785d3fce87007d897786cd96807c27fc3e076cb (patch)
treeaeb4927f05d0866c7811aa7e04521b9d51e4fdfc
parent8752f7116a5841157dc6f978ac5cb469f79146df (diff)
downloadcpython-1785d3fce87007d897786cd96807c27fc3e076cb.zip
cpython-1785d3fce87007d897786cd96807c27fc3e076cb.tar.gz
cpython-1785d3fce87007d897786cd96807c27fc3e076cb.tar.bz2
patch for PSF-2006-001.
-rw-r--r--Misc/NEWS35
-rw-r--r--Objects/unicodeobject.c37
2 files changed, 47 insertions, 25 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 1c3e92a..c1d18ac 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -4,26 +4,22 @@ Python News
(editors: check NEWS.help for information about editing NEWS using ReST.)
-What's New in Python 2.3.6rc1?
-==============================
+What's New in Python 2.3.6c1?
+=============================
-*Release date: XX-XXX-200X*
+*Release date: 25-OCT-2006*
-Extension modules
+Core and builtins
-----------------
-- Apply fix for potential heap overflow in PCRE code (CAN-2005-2491).
-
-
-What's New in Python 2.3.5?
-==============================
-
-*Release date: 08-FEB-2005*
+- Patch #1541585: fix buffer overrun when performing repr() on
+ a unicode string in a build with wide unicode (UCS-4) support.
+ This is the problem described in security advisory PSF-2006-001.
-Core and builtins
+Extension modules
-----------------
-- Partially revert the fix for #1074011; don't try to fflush stdin anymore.
+- Apply fix for potential heap overflow in PCRE code (CAN-2005-2491).
Library
-------
@@ -40,6 +36,19 @@ Library
Also, whereas % values were decoded in all parameter continuations, they are
now only decoded in encoded parameter parts.
+What's New in Python 2.3.5?
+==============================
+
+*Release date: 08-FEB-2005*
+
+Core and builtins
+-----------------
+
+- Partially revert the fix for #1074011; don't try to fflush stdin anymore.
+
+Library
+-------
+
- Applied a security fix to SimpleXMLRPCserver (PSF-2005-001). This
disables recursive traversal through instance attributes, which can
be exploited in various ways.
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 6f3e8b1..e9b2a83 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1888,7 +1888,28 @@ PyObject *unicodeescape_string(const Py_UNICODE *s,
static const char *hexdigit = "0123456789abcdef";
- repr = PyString_FromStringAndSize(NULL, 2 + 6*size + 1);
+ /* Initial allocation is based on the longest-possible unichr
+ escape.
+
+ In wide (UTF-32) builds '\U00xxxxxx' is 10 chars per source
+ unichr, so in this case it's the longest unichr escape. In
+ narrow (UTF-16) builds this is five chars per source unichr
+ since there are two unichrs in the surrogate pair, so in narrow
+ (UTF-16) builds it's not the longest unichr escape.
+
+ In wide or narrow builds '\uxxxx' is 6 chars per source unichr,
+ so in the narrow (UTF-16) build case it's the longest unichr
+ escape.
+ */
+
+ repr = PyString_FromStringAndSize(NULL,
+ 2
+#ifdef Py_UNICODE_WIDE
+ + 10*size
+#else
+ + 6*size
+#endif
+ + 1);
if (repr == NULL)
return NULL;
@@ -1913,15 +1934,6 @@ PyObject *unicodeescape_string(const Py_UNICODE *s,
#ifdef Py_UNICODE_WIDE
/* Map 21-bit characters to '\U00xxxxxx' */
else if (ch >= 0x10000) {
- int offset = p - PyString_AS_STRING(repr);
-
- /* Resize the string if necessary */
- if (offset + 12 > PyString_GET_SIZE(repr)) {
- if (_PyString_Resize(&repr, PyString_GET_SIZE(repr) + 100))
- return NULL;
- p = PyString_AS_STRING(repr) + offset;
- }
-
*p++ = '\\';
*p++ = 'U';
*p++ = hexdigit[(ch >> 28) & 0x0000000F];
@@ -1934,8 +1946,8 @@ PyObject *unicodeescape_string(const Py_UNICODE *s,
*p++ = hexdigit[ch & 0x0000000F];
continue;
}
-#endif
- /* Map UTF-16 surrogate pairs to Unicode \UXXXXXXXX escapes */
+#else
+ /* Map UTF-16 surrogate pairs to '\U00xxxxxx' */
else if (ch >= 0xD800 && ch < 0xDC00) {
Py_UNICODE ch2;
Py_UCS4 ucs;
@@ -1960,6 +1972,7 @@ PyObject *unicodeescape_string(const Py_UNICODE *s,
s--;
size++;
}
+#endif
/* Map 16-bit characters to '\uxxxx' */
if (ch >= 256) {