]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
add overflow checking (closes #23361)
authorBenjamin Peterson <benjamin@python.org>
Tue, 10 Feb 2015 01:58:12 +0000 (20:58 -0500)
committerBenjamin Peterson <benjamin@python.org>
Tue, 10 Feb 2015 01:58:12 +0000 (20:58 -0500)
Misc/NEWS
Modules/_winapi.c

index 5e1dbf04411e3d5f293bc979a5fd456934db2139..7d1dfb82fe16fcc34c0cf83469826503fb8f239e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #23361: Fix possible overflow in Windows subprocess creation code.
+
 - Issue #23363: Fix possible overflow in itertools.permutations.
 
 - Issue #23364: Fix possible overflow in itertools.product.
index c53d55a535fe73e63c9641927d8441bb0dc2e168..5257a1e6152b74a8d6ad181fb2eb06eb574bbfbf 100644 (file)
@@ -513,13 +513,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;