Mercurial > cpython-lru_cache-weakref
diff Modules/arraymodule.c @ 10283:d3bece46486e legacy-trunk
Carefully check for overflow when allocating the memory for fromfile
-- someone tried to pass in sys.maxint and got bitten by the bogus
calculations.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 23 Feb 1999 18:05:22 +0000 |
| parents | 38023a425e48 |
| children | a4768315948d |
line wrap: on
line diff
--- a/Modules/arraymodule.c Tue Feb 23 18:00:56 1999 +0000 +++ b/Modules/arraymodule.c Tue Feb 23 18:05:22 1999 +0000 @@ -935,8 +935,15 @@ char *item = self->ob_item; int itemsize = self->ob_descr->itemsize; int nread; - PyMem_RESIZE(item, char, (self->ob_size + n) * itemsize); + int newlength; + size_t newbytes; + /* Be careful here about overflow */ + if ((newlength = self->ob_size + n) <= 0 || + (newbytes = newlength * itemsize) / itemsize != newlength) + goto nomem; + PyMem_RESIZE(item, char, newbytes); if (item == NULL) { + nomem: PyErr_NoMemory(); return NULL; }
