summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-02-02 23:34:09 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-02-02 23:34:09 (GMT)
commitdee948b359c3a68ab4d6b81319eb2f3548b64c91 (patch)
treebf05ca6298b33151de19da538137390916ade104 /Modules
parent1572944499aa7d399460076bc7872ba9d5324932 (diff)
downloadcpython-dee948b359c3a68ab4d6b81319eb2f3548b64c91.zip
cpython-dee948b359c3a68ab4d6b81319eb2f3548b64c91.tar.gz
cpython-dee948b359c3a68ab4d6b81319eb2f3548b64c91.tar.bz2
Issues #23363, #23364, #23365, #23366: Fixed itertools overflow tests.
Used PyMem_New to check overflow.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/itertoolsmodule.c26
1 files changed, 6 insertions, 20 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index f367423..a9e5709 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -2003,15 +2003,14 @@ product_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
nargs = 0;
} else {
nargs = PyTuple_GET_SIZE(args);
- if (repeat > PY_SSIZE_T_MAX/sizeof(Py_ssize_t) ||
- nargs > PY_SSIZE_T_MAX/(repeat * sizeof(Py_ssize_t))) {
+ if ((size_t)nargs > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)/repeat) {
PyErr_SetString(PyExc_OverflowError, "repeat argument too large");
return NULL;
}
}
npools = nargs * repeat;
- indices = PyMem_Malloc(npools * sizeof(Py_ssize_t));
+ indices = PyMem_New(Py_ssize_t, npools);
if (indices == NULL) {
PyErr_NoMemory();
goto error;
@@ -2335,11 +2334,7 @@ combinations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
goto error;
}
- if (r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) {
- PyErr_SetString(PyExc_OverflowError, "r is too big");
- goto error;
- }
- indices = PyMem_Malloc(r * sizeof(Py_ssize_t));
+ indices = PyMem_New(Py_ssize_t, r);
if (indices == NULL) {
PyErr_NoMemory();
goto error;
@@ -2668,11 +2663,7 @@ cwr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
goto error;
}
- if (r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) {
- PyErr_SetString(PyExc_OverflowError, "r is too big");
- goto error;
- }
- indices = PyMem_Malloc(r * sizeof(Py_ssize_t));
+ indices = PyMem_New(Py_ssize_t, r);
if (indices == NULL) {
PyErr_NoMemory();
goto error;
@@ -3001,13 +2992,8 @@ permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
goto error;
}
- if (n > PY_SSIZE_T_MAX/sizeof(Py_ssize_t) ||
- r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) {
- PyErr_SetString(PyExc_OverflowError, "parameters too large");
- goto error;
- }
- indices = PyMem_Malloc(n * sizeof(Py_ssize_t));
- cycles = PyMem_Malloc(r * sizeof(Py_ssize_t));
+ indices = PyMem_New(Py_ssize_t, n);
+ cycles = PyMem_New(Py_ssize_t, r);
if (indices == NULL || cycles == NULL) {
PyErr_NoMemory();
goto error;