diff options
author | Benjamin Peterson <benjamin@python.org> | 2015-02-10 01:58:52 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2015-02-10 01:58:52 (GMT) |
commit | 22ef9f722e6aa138d047625dd845c9a101c4454d (patch) | |
tree | ed32532d048881fdd1272659fa72aa3e6299ac83 /Modules/_winapi.c | |
parent | 78daf00e3fe8e099cf0e2b7710e8c5878d2d4bcc (diff) | |
parent | 8ce6806498be8aa8ae4bd3d3d83624766557ffad (diff) | |
download | cpython-22ef9f722e6aa138d047625dd845c9a101c4454d.zip cpython-22ef9f722e6aa138d047625dd845c9a101c4454d.tar.gz cpython-22ef9f722e6aa138d047625dd845c9a101c4454d.tar.bz2 |
merge 3.3 (#23361)
Diffstat (limited to 'Modules/_winapi.c')
-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 b755178..d472c9e 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -535,13 +535,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; |