summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-10-29 22:15:05 (GMT)
committerGuido van Rossum <guido@python.org>2007-10-29 22:15:05 (GMT)
commit1c1ac3815716b9db9c41111e65919689b41e6d34 (patch)
treeac779e7252c2455bddeed257fa21b85f6e9a0096 /Objects/stringobject.c
parentdff51b2898145d4f9c5db669db4f9ef5a67ab4b5 (diff)
downloadcpython-1c1ac3815716b9db9c41111e65919689b41e6d34.zip
cpython-1c1ac3815716b9db9c41111e65919689b41e6d34.tar.gz
cpython-1c1ac3815716b9db9c41111e65919689b41e6d34.tar.bz2
Backport fixes for the code that decodes octal escapes (and for PyString
also hex escapes) -- this was reaching beyond the end of the input string buffer, even though it is not supposed to be \0-terminated. This has no visible effect but is clearly the correct thing to do. (In 3.0 it had a visible effect after removing ob_sstate from PyString.)
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r--Objects/stringobject.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 22b50d5..3c14022 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -616,16 +616,18 @@ PyObject *PyString_DecodeEscape(const char *s,
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(Py_CHARMASK(s[0]))
- && isxdigit(Py_CHARMASK(s[1]))) {
+ if (s+1 < end &&
+ isxdigit(Py_CHARMASK(s[0])) &&
+ isxdigit(Py_CHARMASK(s[1])))
+ {
unsigned int x = 0;
c = Py_CHARMASK(*s);
s++;