summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-02-10 02:00:00 (GMT)
committerBenjamin Peterson <benjamin@python.org>2015-02-10 02:00:00 (GMT)
commit5ef01e9b93493a1ca8746b956a70972ef52b3791 (patch)
treebae18fe68e5994768b8a405ee555ba090f092ade
parent365701add94255d753d555c6b3833dd8cc6d43a0 (diff)
parent22ef9f722e6aa138d047625dd845c9a101c4454d (diff)
downloadcpython-5ef01e9b93493a1ca8746b956a70972ef52b3791.zip
cpython-5ef01e9b93493a1ca8746b956a70972ef52b3791.tar.gz
cpython-5ef01e9b93493a1ca8746b956a70972ef52b3791.tar.bz2
merge 3.4 (#23361)
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/_winapi.c14
2 files changed, 14 insertions, 2 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index b34ff5c..12a3762 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,8 @@ Core and Builtins
Library
-------
+- Issue #23361: Fix possible overflow in Windows subprocess creation code.
+
- logging.handlers.QueueListener now takes a respect_handler_level keyword
argument which, if set to True, will pass messages to handlers taking handler
levels into account.
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;