lkml.org 
[lkml]   [2022]   [Jul]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/3] lkdtm/fortify: Check possible NULL pointer returned by kmalloc()
Date
As the possible alloc failure of the kmalloc(),the return pointer
could be NULL,therefore it should be better to check it.

Signed-off-by: Ren Yu <renyu@nfschina.com>
---
drivers/misc/lkdtm/fortify.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/misc/lkdtm/fortify.c b/drivers/misc/lkdtm/fortify.c
index 080293fa3c52..5d70c5ef918b 100644
--- a/drivers/misc/lkdtm/fortify.c
+++ b/drivers/misc/lkdtm/fortify.c
@@ -41,6 +41,9 @@ static void lkdtm_FORTIFIED_SUBOBJECT(void)
char *src;

src = kmalloc(size, GFP_KERNEL);
+ if (!src)
+ return;
+
strscpy(src, "over ten bytes", size);
size = strlen(src) + 1;

--
2.11.0
\
 
 \ /
  Last update: 2022-07-25 10:11    [W:0.027 / U:0.180 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site