Skip to content

Commit 22ef9f7

Browse files
committed
merge 3.3 (python#23361)
2 parents 78daf00 + 8ce6806 commit 22ef9f7

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

Misc/NEWS

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

16+
- Issue #23361: Fix possible overflow in Windows subprocess creation code.
1617

1718
What's New in Python 3.4.3rc1?
1819
==============================

Modules/_winapi.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,23 @@ getenvironment(PyObject* environment)
535535
"environment can only contain strings");
536536
goto error;
537537
}
538+
if (totalsize > PY_SSIZE_T_MAX - PyUnicode_GET_LENGTH(key) - 1) {
539+
PyErr_SetString(PyExc_OverflowError, "environment too long");
540+
goto error;
541+
}
538542
totalsize += PyUnicode_GET_LENGTH(key) + 1; /* +1 for '=' */
543+
if (totalsize > PY_SSIZE_T_MAX - PyUnicode_GET_LENGTH(value) - 1) {
544+
PyErr_SetString(PyExc_OverflowError, "environment too long");
545+
goto error;
546+
}
539547
totalsize += PyUnicode_GET_LENGTH(value) + 1; /* +1 for '\0' */
540548
}
541549

542-
buffer = PyMem_Malloc(totalsize * sizeof(Py_UCS4));
543-
if (! buffer)
550+
buffer = PyMem_NEW(Py_UCS4, totalsize);
551+
if (! buffer) {
552+
PyErr_NoMemory();
544553
goto error;
554+
}
545555
p = buffer;
546556
end = buffer + totalsize;
547557

0 commit comments

Comments
 (0)