From f21c2a4aea59b4825a11f5d586c25619031b9836 Mon Sep 17 00:00:00 2001 From: zfx Date: Tue, 8 Jun 2021 10:06:23 +0800 Subject: [PATCH] check the max size of memory malloc --- osal/src/osal_mem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/osal/src/osal_mem.c b/osal/src/osal_mem.c index a41f363..045b18a 100644 --- a/osal/src/osal_mem.c +++ b/osal/src/osal_mem.c @@ -48,6 +48,11 @@ static void *osal_mem_alloc(size_t size, uint32_t *type) char *base = NULL; const uint32_t mng_size = sizeof(struct mem_block); + if (size > (SIZE_MAX - mng_size)) { + HDF_LOGE("%s invalid param %d", __func__, size); + return NULL; + } + if (size > (KMALLOC_SIZE - mng_size)) { base = (char *)vmalloc(size + mng_size); *type = TYPE_VMALLOC; -- Gitee