diff options
author | GONG, Ruiqi <gongruiqi1@huawei.com> | 2022-06-06 11:17:14 +0300 |
---|---|---|
committer | Casey Schaufler <casey@schaufler-ca.com> | 2022-08-01 21:26:09 +0300 |
commit | 63c3b5d2ca96b4a2a88ae01bea94021e874ce8fe (patch) | |
tree | 6f983efef5d8cfc22f1e5b1c2f380db4fd922fc1 | |
parent | f2906aa863381afb0015a9eb7fefad885d4e5a56 (diff) | |
download | linux-63c3b5d2ca96b4a2a88ae01bea94021e874ce8fe.tar.xz |
smack: Replace kzalloc + strncpy with kstrndup
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 <gongruiqi1@huawei.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
-rw-r--r-- | security/smack/smack_access.c | 7 |
1 files 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; } |