[Python-checkins] r62261 - python/trunk/Objects/bytesobject.c python/trunk/Objects/stringobject.c python/trunk/Objects/unicodeobject.c

gregory.p.smith python-checkins at python.org
Thu Apr 10 01:16:38 CEST 2008


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


More information about the Python-checkins mailing list