diff mbox series

kunit: tool: add null pointer check

Message ID 20220329103919.2376818-1-lv.ruyi@zte.com.cn
State New
Headers show
Series kunit: tool: add null pointer check | expand

Commit Message

Lv Ruyi March 29, 2022, 10:39 a.m. UTC
From: Lv Ruyi <lv.ruyi@zte.com.cn>

kmalloc and kcalloc is a memory allocation function which can return NULL
when some internal memory errors happen. Add null pointer check to avoid
dereferencing null pointer.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
---
 lib/kunit/executor.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c
index 22640c9ee819..be21d0451367 100644
--- a/lib/kunit/executor.c
+++ b/lib/kunit/executor.c
@@ -71,9 +71,13 @@  kunit_filter_tests(struct kunit_suite *const suite, const char *test_glob)
 
 	/* Use memcpy to workaround copy->name being const. */
 	copy = kmalloc(sizeof(*copy), GFP_KERNEL);
+	if (!copy)
+		return NULL;
 	memcpy(copy, suite, sizeof(*copy));
 
 	filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL);
+	if (!filtered)
+		return NULL;
 
 	n = 0;
 	kunit_suite_for_each_test_case(suite, test_case) {