summaryrefslogtreecommitdiff
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-08-19 16:46:30 +0000
committerGuido van Rossum <guido@python.org>1992-08-19 16:46:30 +0000
commite9c5379ab46c3706148ee459e3b6aa5625545d8b (patch)
tree2afa725a3a344c2350902947c30f59d1a22e00ff /Objects/listobject.c
parentc1b94e32f1db10ee3964dc8981f459f3b6e61412 (diff)
downloadcpython-e9c5379ab46c3706148ee459e3b6aa5625545d8b.tar.gz
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
argument to malloc() (size_t or unsigned int) * listobject.c: check for overflow of the size of the object, so things like range(0x7fffffff) will raise MemoryError instead of calling malloc() with -4 (and then crashing -- malloc's fault)
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r--Objects/listobject.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 0f517359de..c032532284 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -34,10 +34,16 @@ newlistobject(size)
{
int i;
listobject *op;
+ MALLARG nbytes;
if (size < 0) {
err_badcall();
return NULL;
}
+ nbytes = size * sizeof(object *);
+ /* Check for overflow */
+ if (nbytes / sizeof(object *) != size) {
+ return err_nomem();
+ }
op = (listobject *) malloc(sizeof(listobject));
if (op == NULL) {
return err_nomem();
@@ -46,7 +52,7 @@ newlistobject(size)
op->ob_item = NULL;
}
else {
- op->ob_item = (object **) malloc(size * sizeof(object *));
+ op->ob_item = (object **) malloc(nbytes);
if (op->ob_item == NULL) {
free((ANY *)op);
return err_nomem();