From 3641c25df93b34f53a5d40a2f0688e4b6e4de355 Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Wed, 1 Aug 2018 14:44:20 -0700 Subject: [PATCH] libc: minimal: fix calloc() calloc() wasn't zeroing out the allocated memory as it is supposed to. Fixes: #9221 Signed-off-by: Andrew Boie --- lib/libc/minimal/source/stdlib/malloc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/libc/minimal/source/stdlib/malloc.c b/lib/libc/minimal/source/stdlib/malloc.c index 037447eb36..966b6411a8 100644 --- a/lib/libc/minimal/source/stdlib/malloc.c +++ b/lib/libc/minimal/source/stdlib/malloc.c @@ -73,11 +73,20 @@ static bool size_t_mul_overflow(size_t a, size_t b, size_t *res) void *calloc(size_t nmemb, size_t size) { + void *ret; + if (size_t_mul_overflow(nmemb, size, &size)) { errno = ENOMEM; return NULL; } - return malloc(size); + + ret = malloc(size); + + if (ret) { + memset(ret, 0, size); + } + + return ret; } void *realloc(void *ptr, size_t requested_size)