Kaydet (Commit) eb3f00ae authored tarafından Martin v. Löwis's avatar Martin v. Löwis

Check for trailing backslash. Fixes #593656.

üst 8a8da798
...@@ -199,6 +199,7 @@ class AbstractPickleTests(unittest.TestCase): ...@@ -199,6 +199,7 @@ class AbstractPickleTests(unittest.TestCase):
"'abc", # quote is not closed "'abc", # quote is not closed
"'abc\"", # open quote and close quote don't match "'abc\"", # open quote and close quote don't match
"'abc' ?", # junk after close quote "'abc' ?", # junk after close quote
"'\\'", # trailing backslash
# some tests of the quoting rules # some tests of the quoting rules
#"'abc\"\''", #"'abc\"\''",
#"'\\\\a\'\'\'\\\'\\\\\''", #"'\\\\a\'\'\'\\\'\\\\\''",
......
...@@ -546,6 +546,11 @@ PyObject *PyString_DecodeEscape(const char *s, ...@@ -546,6 +546,11 @@ PyObject *PyString_DecodeEscape(const char *s,
continue; continue;
} }
s++; s++;
if (s==end) {
PyErr_SetString(PyExc_ValueError,
"Trailing \\ in string");
goto failed;
}
switch (*s++) { switch (*s++) {
/* XXX This assumes ASCII! */ /* XXX This assumes ASCII! */
case '\n': break; case '\n': break;
...@@ -594,10 +599,9 @@ PyObject *PyString_DecodeEscape(const char *s, ...@@ -594,10 +599,9 @@ PyObject *PyString_DecodeEscape(const char *s,
break; break;
} }
if (!errors || strcmp(errors, "strict") == 0) { if (!errors || strcmp(errors, "strict") == 0) {
Py_DECREF(v);
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"invalid \\x escape"); "invalid \\x escape");
return NULL; goto failed;
} }
if (strcmp(errors, "replace") == 0) { if (strcmp(errors, "replace") == 0) {
*p++ = '?'; *p++ = '?';
...@@ -608,18 +612,17 @@ PyObject *PyString_DecodeEscape(const char *s, ...@@ -608,18 +612,17 @@ PyObject *PyString_DecodeEscape(const char *s,
"decoding error; " "decoding error; "
"unknown error handling code: %.400s", "unknown error handling code: %.400s",
errors); errors);
return NULL; goto failed;
} }
#ifndef Py_USING_UNICODE #ifndef Py_USING_UNICODE
case 'u': case 'u':
case 'U': case 'U':
case 'N': case 'N':
if (unicode) { if (unicode) {
Py_DECREF(v);
com_error(com, PyExc_ValueError, com_error(com, PyExc_ValueError,
"Unicode escapes not legal " "Unicode escapes not legal "
"when Unicode disabled"); "when Unicode disabled");
return NULL; goto failed;
} }
#endif #endif
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment