]> granicus.if.org Git - python/commitdiff
Check whether the strlen() result overflows Py_ssize_t.
authorWalter Dörwald <walter@livinglogic.de>
Sun, 6 May 2007 10:00:02 +0000 (10:00 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Sun, 6 May 2007 10:00:02 +0000 (10:00 +0000)
Objects/unicodeobject.c

index af98a90efbd99d1628b241c2a965eaf29638e84e..9dc96da73c7f97c1d01a55bbaf878f866edd760f 100644 (file)
@@ -396,7 +396,11 @@ PyObject *PyUnicode_FromUnicode(const Py_UNICODE *u,
 PyObject *PyUnicode_FromString(const char *u)
 {
     PyUnicodeObject *unicode;
-    Py_ssize_t size = strlen(u);
+    size_t size = strlen(u);
+    if (size > PY_SSIZE_T_MAX) {
+        PyErr_SetString(PyExc_OverflowError, "input too long");
+        return NULL;
+    }
 
     /* If the Unicode data is known at construction time, we can apply
        some optimizations which share commonly used objects. */