Mercurial > cpython-lru_cache-weakref
diff Objects/tupleobject.c @ 48114:c4d24fc8ba8a legacy-trunk
Security patches from Apple: prevent int overflow when allocating memory
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Thu, 31 Jul 2008 17:17:14 +0000 |
| parents | 2dfaa0683be8 |
| children | 2e794757bdc8 |
line wrap: on
line diff
--- a/Objects/tupleobject.c Thu Jul 31 15:15:45 2008 +0000 +++ b/Objects/tupleobject.c Thu Jul 31 17:17:14 2008 +0000 @@ -60,11 +60,12 @@ Py_ssize_t nbytes = size * sizeof(PyObject *); /* Check for overflow */ if (nbytes / sizeof(PyObject *) != (size_t)size || - (nbytes += sizeof(PyTupleObject) - sizeof(PyObject *)) - <= 0) + (nbytes > PY_SSIZE_T_MAX - sizeof(PyTupleObject) - sizeof(PyObject *))) { return PyErr_NoMemory(); } + nbytes += sizeof(PyTupleObject) - sizeof(PyObject *); + op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size); if (op == NULL) return NULL;
