diff options
author | Benjamin Peterson <benjamin@python.org> | 2015-02-10 02:00:00 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2015-02-10 02:00:00 (GMT) |
commit | 5ef01e9b93493a1ca8746b956a70972ef52b3791 (patch) | |
tree | bae18fe68e5994768b8a405ee555ba090f092ade /Modules | |
parent | 365701add94255d753d555c6b3833dd8cc6d43a0 (diff) | |
parent | 22ef9f722e6aa138d047625dd845c9a101c4454d (diff) | |
download | cpython-5ef01e9b93493a1ca8746b956a70972ef52b3791.zip cpython-5ef01e9b93493a1ca8746b956a70972ef52b3791.tar.gz cpython-5ef01e9b93493a1ca8746b956a70972ef52b3791.tar.bz2 |
merge 3.4 (#23361)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_winapi.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Modules/_winapi.c b/Modules/_winapi.c index f118436..51c4d5f 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -670,13 +670,23 @@ getenvironment(PyObject* environment) "environment can only contain strings"); goto error; } + if (totalsize > PY_SSIZE_T_MAX - PyUnicode_GET_LENGTH(key) - 1) { + PyErr_SetString(PyExc_OverflowError, "environment too long"); + goto error; + } totalsize += PyUnicode_GET_LENGTH(key) + 1; /* +1 for '=' */ + if (totalsize > PY_SSIZE_T_MAX - PyUnicode_GET_LENGTH(value) - 1) { + PyErr_SetString(PyExc_OverflowError, "environment too long"); + goto error; + } totalsize += PyUnicode_GET_LENGTH(value) + 1; /* +1 for '\0' */ } - buffer = PyMem_Malloc(totalsize * sizeof(Py_UCS4)); - if (! buffer) + buffer = PyMem_NEW(Py_UCS4, totalsize); + if (! buffer) { + PyErr_NoMemory(); goto error; + } p = buffer; end = buffer + totalsize; |