summaryrefslogtreecommitdiff
path: root/malloc.c
diff options
context:
space:
mode:
authorXi Wang <xi.wang@gmail.com>2012-03-14 21:46:49 +0100
committerIvan Maidanski <ivmai@mail.ru>2012-03-15 16:46:02 +0100
commit65c0ef9421c5590be48b48f1f9c18e86c99ad1fa (patch)
tree351dcc8bb09e00010fa41bc1c1a80b2f0039e545 /malloc.c
parent9a52167341678e24cb1fecd94f719b78e0311fc8 (diff)
Fix calloc() overflow
* malloc.c (calloc): Check multiplication overflow in calloc(), assuming REDIRECT_MALLOC.
Diffstat (limited to 'malloc.c')
-rw-r--r--malloc.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/malloc.c b/malloc.c
index aeda693..5c3374d 100644
--- a/malloc.c
+++ b/malloc.c
@@ -369,8 +369,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. */