]> granicus.if.org Git - python/commitdiff
Check for trailing backslash. Fixes #593656.
authorMartin v. Löwis <martin@v.loewis.de>
Wed, 14 Aug 2002 08:22:50 +0000 (08:22 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Wed, 14 Aug 2002 08:22:50 +0000 (08:22 +0000)
Lib/test/pickletester.py
Objects/stringobject.c

index 3dc7901c0be06271fc5f070263e19dc788a1b874..2294c3dd0f8897b48b193fd79088dd717c86238b 100644 (file)
@@ -199,6 +199,7 @@ class AbstractPickleTests(unittest.TestCase):
                     "'abc", # quote is not closed
                     "'abc\"", # open quote and close quote don't match
                     "'abc'   ?", # junk after close quote
+                    "'\\'", # trailing backslash
                     # some tests of the quoting rules
                     #"'abc\"\''",
                     #"'\\\\a\'\'\'\\\'\\\\\''",
index 19c28346d31ae372df93d432416fec3892ace9b1..a21e021d925e0dce77fe4ebb3a3adbee59a05d03 100644 (file)
@@ -546,6 +546,11 @@ PyObject *PyString_DecodeEscape(const char *s,
                        continue;
                }
                s++;
+                if (s==end) {
+                       PyErr_SetString(PyExc_ValueError,
+                                       "Trailing \\ in string");
+                       goto failed;
+               }
                switch (*s++) {
                /* XXX This assumes ASCII! */
                case '\n': break;
@@ -594,10 +599,9 @@ PyObject *PyString_DecodeEscape(const char *s,
                                break;
                        }
                        if (!errors || strcmp(errors, "strict") == 0) {
-                               Py_DECREF(v);
                                PyErr_SetString(PyExc_ValueError, 
                                                "invalid \\x escape");
-                               return NULL;
+                               goto failed;
                        }
                        if (strcmp(errors, "replace") == 0) {
                                *p++ = '?';
@@ -608,18 +612,17 @@ PyObject *PyString_DecodeEscape(const char *s,
                                             "decoding error; "
                                             "unknown error handling code: %.400s",
                                             errors);
-                               return NULL;
+                               goto failed;
                        }
 #ifndef Py_USING_UNICODE
                case 'u':
                case 'U':
                case 'N':
                        if (unicode) {
-                               Py_DECREF(v);
                                com_error(com, PyExc_ValueError,
                                          "Unicode escapes not legal "
                                          "when Unicode disabled");
-                               return NULL;
+                               goto failed;
                        }
 #endif
                default: