diff Objects/stringobject.c @ 24809:c75cdc471b22 legacy-trunk

Check for trailing backslash. Fixes #593656.
author Martin v. Löwis <martin@v.loewis.de>
date Wed, 14 Aug 2002 08:22:50 +0000
parents ab63af3ec349
children a602e4878b4e
line wrap: on
line diff
--- a/Objects/stringobject.c	Wed Aug 14 07:46:28 2002 +0000
+++ b/Objects/stringobject.c	Wed Aug 14 08:22:50 2002 +0000
@@ -546,6 +546,11 @@
 			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 @@
 				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 @@
 					     "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: