summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2008-04-09 23:16:37 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2008-04-09 23:16:37 (GMT)
commitc00eb73a309d5e9a4e89c3114b32eda88bd83e98 (patch)
treefaec1107bc64ecfc8f230d9f294a02503a530e45 /Objects/unicodeobject.c
parentf10832005599cb78b20ccbae63adf8a9450ba2bf (diff)
downloadcpython-c00eb73a309d5e9a4e89c3114b32eda88bd83e98.zip
cpython-c00eb73a309d5e9a4e89c3114b32eda88bd83e98.tar.gz
cpython-c00eb73a309d5e9a4e89c3114b32eda88bd83e98.tar.bz2
Raise SystemError when size < 0 is passed into PyString_FromStringAndSize,
PyBytes_FromStringAndSize or PyUnicode_FromStringAndSize. [issue2587]
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 75ad9f0..4337972 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -465,6 +465,14 @@ PyObject *PyUnicode_FromUnicode(const Py_UNICODE *u,
PyObject *PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size)
{
PyUnicodeObject *unicode;
+
+ assert(size <= 0);
+ if (size < 0) {
+ PyErr_SetString(PyExc_SystemError,
+ "Negative size passed to PyUnicode_FromStringAndSize");
+ return NULL;
+ }
+
/* If the Unicode data is known at construction time, we can apply
some optimizations which share commonly used objects.
Also, this means the input must be UTF-8, so fall back to the