summaryrefslogtreecommitdiff
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2008-04-09 23:41:13 +0000
committerGregory P. Smith <greg@mad-scientist.com>2008-04-09 23:41:13 +0000
commit14acde30f634c1b52e498e29dd772c4fa9f41380 (patch)
treeb630b6689e7b4e4f2e3ea92c7f40c1fb85b82d35 /Objects/stringobject.c
parent3782da4e0a0bec3def64eda045d76bd1943ccaf1 (diff)
downloadcpython-git-14acde30f634c1b52e498e29dd772c4fa9f41380.tar.gz
Backport r62261 from trunk:
Prevent PyString_FromStringAndSize() from passing negative sizes on to lower level memory allocation functions. Raise a SystemError and return NULL instead.
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r--Objects/stringobject.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index e1e287fba1..7cd613dd87 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -54,6 +54,11 @@ PyString_FromStringAndSize(const char *str, Py_ssize_t size)
{
register PyStringObject *op;
assert(size >= 0);
+ if (size < 0) {
+ PyErr_SetString(PyExc_SystemError,
+ "Negative size passed to PyString_FromStringAndSize");
+ return NULL;
+ }
if (size == 0 && (op = nullstring) != NULL) {
#ifdef COUNT_ALLOCS
null_strings++;