]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
smack: Replace kzalloc + strncpy with kstrndup
authorGONG, Ruiqi <gongruiqi1@huawei.com>
Mon, 6 Jun 2022 08:17:14 +0000 (16:17 +0800)
committerCasey Schaufler <casey@schaufler-ca.com>
Mon, 1 Aug 2022 18:26:09 +0000 (11:26 -0700)
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>
security/smack/smack_access.c

index d2186e2757be81e38457a9dd566d8cf74bae1529..585e5e35710b247d877fd1bf0fd68da8aff550e2 100644 (file)
@@ -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;
 }