Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

GONG, Ruiqi and committed by
Casey Schaufler
63c3b5d2 f2906aa8

+2 -5
+2 -5
security/smack/smack_access.c
··· 465 465 if (i == 0 || i >= SMK_LONGLABEL) 466 466 return ERR_PTR(-EINVAL); 467 467 468 - smack = kzalloc(i + 1, GFP_NOFS); 469 - if (smack == NULL) 468 + smack = kstrndup(string, i, GFP_NOFS); 469 + if (!smack) 470 470 return ERR_PTR(-ENOMEM); 471 - 472 - strncpy(smack, string, i); 473 - 474 471 return smack; 475 472 } 476 473