Author: guido.van.rossum
Date: Mon Oct 29 23:05:21 2007
New Revision: 58708

Modified:
   python/branches/py3k-pep3137/Objects/stringobject.c
   python/branches/py3k-pep3137/Objects/unicodeobject.c
Log:
Supplemental fix for issue 1359.
Also fixing it for PyString, which has the same issue (and also for \x!).


Modified: python/branches/py3k-pep3137/Objects/stringobject.c
==============================================================================
--- python/branches/py3k-pep3137/Objects/stringobject.c (original)
+++ python/branches/py3k-pep3137/Objects/stringobject.c Mon Oct 29 23:05:21 2007
@@ -409,15 +409,15 @@
                case '0': case '1': case '2': case '3':
                case '4': case '5': case '6': case '7':
                        c = s[-1] - '0';
-                       if ('0' <= *s && *s <= '7') {
+                       if (s < end && '0' <= *s && *s <= '7') {
                                c = (c<<3) + *s++ - '0';
-                               if ('0' <= *s && *s <= '7')
+                               if (s < end && '0' <= *s && *s <= '7')
                                        c = (c<<3) + *s++ - '0';
                        }
                        *p++ = c;
                        break;
                case 'x':
-                       if (ISXDIGIT(s[0]) && ISXDIGIT(s[1])) {
+                       if (s+1 < end && ISXDIGIT(s[0]) && ISXDIGIT(s[1])) {
                                unsigned int x = 0;
                                c = Py_CHARMASK(*s);
                                s++;

Modified: python/branches/py3k-pep3137/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-pep3137/Objects/unicodeobject.c        (original)
+++ python/branches/py3k-pep3137/Objects/unicodeobject.c        Mon Oct 29 
23:05:21 2007
@@ -2671,8 +2671,10 @@
         startinpos = s-starts;
         /* \ - Escapes */
         s++;
-        assert (s < end); /* If this fails, the parser let through garbage */
-        switch (*s++) {
+        c = *s++;
+        if (s > end)
+            c = '\0'; /* Invalid after \ */
+        switch (c) {
 
         /* \x escapes */
         case '\n': break;
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to