mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-18 20:04:16 +08:00
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>
This commit is contained in:
parent
f2906aa863
commit
63c3b5d2ca
@ -465,12 +465,9 @@ char *smk_parse_smack(const char *string, int len)
|
|||||||
if (i == 0 || i >= SMK_LONGLABEL)
|
if (i == 0 || i >= SMK_LONGLABEL)
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
smack = kzalloc(i + 1, GFP_NOFS);
|
smack = kstrndup(string, i, GFP_NOFS);
|
||||||
if (smack == NULL)
|
if (!smack)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
strncpy(smack, string, i);
|
|
||||||
|
|
||||||
return smack;
|
return smack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user