Skip to content

Commit

Permalink
smack: Replace kzalloc + strncpy with kstrndup
Browse files Browse the repository at this point in the history
Simplify the code by using kstrndup instead of kzalloc and strncpy in
smk_parse_smack(), which meanwhile remove strncpy as [1] suggests.

[1]: KSPP/linux#90

Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
  • Loading branch information
GONG, Ruiqi authored and cschaufler committed Aug 1, 2022
1 parent f2906aa commit 63c3b5d
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions security/smack/smack_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 63c3b5d

Please sign in to comment.