[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20230614144440.113375-1-cymi20@fudan.edu.cn>
Date: Wed, 14 Jun 2023 07:44:40 -0700
From: Chenyuan Mi <cymi20@...an.edu.cn>
To: andrii@...nel.org
Cc: daniel@...earbox.net, ast@...nel.org, acme@...hat.com,
irogers@...gle.com, linux-kernel@...r.kernel.org,
Chenyuan Mi <cymi20@...an.edu.cn>
Subject: [PATCH] tools: Fix missing check for return value of malloc()
The malloc() function may return NULL when it fails,
which may cause null pointer deference in kmalloc(),
add Null check for return value of malloc().
Found by our static analysis tool.
Signed-off-by: Chenyuan Mi <cymi20@...an.edu.cn>
---
tools/lib/slab.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/lib/slab.c b/tools/lib/slab.c
index 959997fb0652..cee98eb0a6d6 100644
--- a/tools/lib/slab.c
+++ b/tools/lib/slab.c
@@ -19,6 +19,8 @@ void *kmalloc(size_t size, gfp_t gfp)
return NULL;
ret = malloc(size);
+ if (!ret)
+ return NULL;
uatomic_inc(&kmalloc_nr_allocated);
if (kmalloc_verbose)
printf("Allocating %p from malloc\n", ret);
--
2.17.1
Powered by blists - more mailing lists