From: Xi Wang Date: Wed, 14 Mar 2012 20:46:49 +0000 (+0800) Subject: Fix calloc() overflow X-Git-Tag: gc7_3alpha2~57 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e10c1eb;p=gc Fix calloc() overflow * malloc.c (calloc): Check multiplication overflow in calloc(), assuming REDIRECT_MALLOC. --- diff --git a/malloc.c b/malloc.c index da68f133..cc0cc001 100644 --- a/malloc.c +++ b/malloc.c @@ -372,8 +372,13 @@ void * malloc(size_t lb) } #endif /* GC_LINUX_THREADS */ +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif void * calloc(size_t n, size_t lb) { + if (lb && n > SIZE_MAX / lb) + return NULL; # if defined(GC_LINUX_THREADS) /* && !defined(USE_PROC_FOR_LIBRARIES) */ /* libpthread allocated some memory that is only pointed to by */ /* mmapped thread stacks. Make sure it's not collectable. */