From e21a3e783cefa566f73c9734c180b12beeb4a00d Mon Sep 17 00:00:00 2001 From: Rot127 Date: Sun, 28 Jun 2026 18:23:51 +0200 Subject: [PATCH] Add overflow check to cs_kern_os_calloc Co-authored by: orbisai0security --- cs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cs.c b/cs.c index a70c9e8a52..79da234be6 100644 --- a/cs.c +++ b/cs.c @@ -344,7 +344,11 @@ extern void* kern_os_realloc(void* addr, size_t nsize); static void* cs_kern_os_calloc(size_t num, size_t size) { - return kern_os_malloc(num * size); // malloc bzeroes the buffer + size_t alloc = num * size; + if (num && size != alloc / num) { + return NULL; // overflow check + } + return kern_os_malloc(alloc); // malloc bzeroes the buffer } cs_malloc_t cs_mem_malloc = kern_os_malloc;