summaryrefslogtreecommitdiff
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2018-01-10 21:49:45 +0000
committerConrad Meyer <cem@FreeBSD.org>2018-01-10 21:49:45 +0000
commitc02fc9607a219ec673b148cdfc211b15ce687b80 (patch)
treecc8bdb3cc975cba9036f97a8eeb0301907c950c7 /sys/kern/kern_malloc.c
parent60eddb209b5ad13a549ca74a41b7cb38a31da5ef (diff)
Notes
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 94be535a71c9..010b1ee8799b 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -535,18 +535,12 @@ malloc(unsigned long size, struct malloc_type *mtp, int flags)
return ((void *) va);
}
-/*
- * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
- * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
- */
-#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 8 / 2))
void *
mallocarray(size_t nmemb, size_t size, struct malloc_type *type, int flags)
{
- if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
- nmemb > 0 && SIZE_MAX / nmemb < size)
- return (NULL);
+ if (WOULD_OVERFLOW(nmemb, size))
+ panic("mallocarray: %zu * %zu overflowed", nmemb, size);
return (malloc(size * nmemb, type, flags));
}