summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-08-19 16:46:30 (GMT)
committerGuido van Rossum <guido@python.org>1992-08-19 16:46:30 (GMT)
commit1e28e5e59634f56cdeaff528afb122a5735adf09 (patch)
tree2afa725a3a344c2350902947c30f59d1a22e00ff /Objects/listobject.c
parentb001f7adb16e054baa31213e4609b3be2138cade (diff)
downloadcpython-1e28e5e59634f56cdeaff528afb122a5735adf09.zip
cpython-1e28e5e59634f56cdeaff528afb122a5735adf09.tar.gz
cpython-1e28e5e59634f56cdeaff528afb122a5735adf09.tar.bz2
* 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 0f51735..c032532 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();