From: Walter Dörwald Date: Sun, 6 May 2007 10:00:02 +0000 (+0000) Subject: Check whether the strlen() result overflows Py_ssize_t. X-Git-Tag: v3.0a1~1004 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a14c4bbbaa2a3c20e92edbd8fcf162a593474209;p=thirdparty%2FPython%2Fcpython.git Check whether the strlen() result overflows Py_ssize_t. --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index af98a90efbd9..9dc96da73c7f 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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. */