Thread (1 message) 1 message, 1 author, 2022-06-07

Re: [PATCH] smack: Replace kzalloc + strncpy with kstrndup

From: Casey Schaufler <casey@schaufler-ca.com>
Date: 2022-06-07 13:48:12
Also in: lkml

On 6/6/2022 1:17 AM, GONG, Ruiqi wrote:
From: "GONG, Ruiqi" <redacted>

Simplify the code by using kstrndup instead of kzalloc and strncpy in
smk_parse_smack(), which meanwhile remove strncpy as [1] suggests.

[1]: https://github.com/KSPP/linux/issues/90

Signed-off-by: GONG, Ruiqi <redacted>
Thank you. I will take this for the Smack tree.
quoted hunk
---
  security/smack/smack_access.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c
index d2186e2757be..585e5e35710b 100644
--- a/security/smack/smack_access.c
+++ b/security/smack/smack_access.c
@@ -465,12 +465,9 @@ char *smk_parse_smack(const char *string, int len)
  	if (i == 0 || i >= SMK_LONGLABEL)
  		return ERR_PTR(-EINVAL);
  
-	smack = kzalloc(i + 1, GFP_NOFS);
-	if (smack == NULL)
+	smack = kstrndup(string, i, GFP_NOFS);
+	if (!smack)
  		return ERR_PTR(-ENOMEM);
-
-	strncpy(smack, string, i);
-
  	return smack;
  }
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help