Skip to content

Commit 5ef01e9

Browse files
committed
merge 3.4 (python#23361)
2 parents 365701a + 22ef9f7 commit 5ef01e9

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎Misc/NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #23361: Fix possible overflow in Windows subprocess creation code.
17+
1618
- logging.handlers.QueueListener now takes a respect_handler_level keyword
1719
argument which, if set to True, will pass messages to handlers taking handler
1820
levels into account.

‎Modules/_winapi.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,23 @@ getenvironment(PyObject* environment)
670670
"environment can only contain strings");
671671
goto error;
672672
}
673+
if (totalsize > PY_SSIZE_T_MAX - PyUnicode_GET_LENGTH(key) - 1) {
674+
PyErr_SetString(PyExc_OverflowError, "environment too long");
675+
goto error;
676+
}
673677
totalsize += PyUnicode_GET_LENGTH(key) + 1; /* +1 for '=' */
678+
if (totalsize > PY_SSIZE_T_MAX - PyUnicode_GET_LENGTH(value) - 1) {
679+
PyErr_SetString(PyExc_OverflowError, "environment too long");
680+
goto error;
681+
}
674682
totalsize += PyUnicode_GET_LENGTH(value) + 1; /* +1 for '\0' */
675683
}
676684

677-
buffer = PyMem_Malloc(totalsize * sizeof(Py_UCS4));
678-
if (! buffer)
685+
buffer = PyMem_NEW(Py_UCS4, totalsize);
686+
if (! buffer) {
687+
PyErr_NoMemory();
679688
goto error;
689+
}
680690
p = buffer;
681691
end = buffer + totalsize;
682692

0 commit comments

Comments
 (0)