summaryrefslogtreecommitdiff
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2002-09-03 13:53:40 +0000
committerWalter Dörwald <walter@livinglogic.de>2002-09-03 13:53:40 +0000
commit862b378e21afb4e05e0e5e7ccf23451050109864 (patch)
tree2c845d8ebc6816a6b6d0caa684134d110e5e26c5 /Objects/stringobject.c
parent36b0f7798a21a2be65cdb691b0236b48e73d88fe (diff)
downloadcpython-862b378e21afb4e05e0e5e7ccf23451050109864.tar.gz
Check whether a string resize is necessary at the end
of PyString_DecodeEscape(). This prevents a call to _PyString_Resize() for the empty string, which would result in a PyErr_BadInternalCall(), because the empty string has more than one reference. This closes SF bug http://www.python.org/sf/603937
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r--Objects/stringobject.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 31f188a5b9..dd38ee3c85 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -533,8 +533,8 @@ PyObject *PyString_DecodeEscape(const char *s,
char *p, *buf;
const char *end;
PyObject *v;
- v = PyString_FromStringAndSize((char *)NULL,
- recode_encoding ? 4*len:len);
+ int newlen = recode_encoding ? 4*len:len;
+ v = PyString_FromStringAndSize((char *)NULL, newlen);
if (v == NULL)
return NULL;
p = buf = PyString_AsString(v);
@@ -660,7 +660,8 @@ PyObject *PyString_DecodeEscape(const char *s,
break;
}
}
- _PyString_Resize(&v, (int)(p - buf));
+ if (p-buf < newlen)
+ _PyString_Resize(&v, (int)(p - buf));
return v;
failed:
Py_DECREF(v);