[Python-checkins] r62261 - python/trunk/Objects/bytesobject.c python/trunk/Objects/stringobject.c python/trunk/Objects/unicodeobject.c
Jeff Balogh
its.jeff.balogh at gmail.com
Thu Apr 10 01:43:28 CEST 2008
checkins wrote:
> Author: gregory.p.smith
> Date: Thu Apr 10 01:16:37 2008
> New Revision: 62261
>
> Modified:
> python/trunk/Objects/bytesobject.c
> python/trunk/Objects/stringobject.c
> python/trunk/Objects/unicodeobject.c
> Log:
> Raise SystemError when size < 0 is passed into PyString_FromStringAndSize,
> PyBytes_FromStringAndSize or PyUnicode_FromStringAndSize. [issue2587]
>
>
> Modified: python/trunk/Objects/bytesobject.c
> ==============================================================================
> --- python/trunk/Objects/bytesobject.c (original)
> +++ python/trunk/Objects/bytesobject.c Thu Apr 10 01:16:37 2008
> @@ -161,6 +161,11 @@
> Py_ssize_t alloc;
>
> assert(size >= 0);
> + if (size < 0) {
> + PyErr_SetString(PyExc_SystemError,
> + "Negative size passed to PyBytes_FromStringAndSize");
> + return NULL;
> + }
>
> new = PyObject_New(PyBytesObject, &PyBytes_Type);
> if (new == NULL)
>
> Modified: python/trunk/Objects/stringobject.c
> ==============================================================================
> --- python/trunk/Objects/stringobject.c (original)
> +++ python/trunk/Objects/stringobject.c Thu Apr 10 01:16:37 2008
> @@ -56,6 +56,11 @@
> {
> 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++;
>
> Modified: python/trunk/Objects/unicodeobject.c
> ==============================================================================
> --- python/trunk/Objects/unicodeobject.c (original)
> +++ python/trunk/Objects/unicodeobject.c Thu Apr 10 01:16:37 2008
> @@ -465,6 +465,14 @@
> 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
The assert is backwards in the last hunk (unicodeobject.c). It should be
assert(size >= 0);
Patch attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gt-fix.patch
Type: application/octet-stream
Size: 404 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-checkins/attachments/20080409/e5cb4279/attachment-0001.obj
More information about the Python-checkins
mailing list