From: Xu Panda Date: Sat, 3 Dec 2022 06:19:32 +0000 (+0800) Subject: x86/mce/dev-mcelog: use strscpy() to instead of strncpy() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=7ddf0050a21fdcc025c3cb1055fe3db60df1cd97;p=linux.git x86/mce/dev-mcelog: use strscpy() to instead of strncpy() The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings. Signed-off-by: Xu Panda Signed-off-by: Yang Yang Signed-off-by: Ingo Molnar Reviewed-by: Tony Luck Link: https://lore.kernel.org/r/202212031419324523731@zte.com.cn --- diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c index 100fbeebdc728..a05ac0716ecfb 100644 --- a/arch/x86/kernel/cpu/mce/dev-mcelog.c +++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c @@ -105,8 +105,7 @@ static ssize_t set_trigger(struct device *s, struct device_attribute *attr, { char *p; - strncpy(mce_helper, buf, sizeof(mce_helper)); - mce_helper[sizeof(mce_helper)-1] = 0; + strscpy(mce_helper, buf, sizeof(mce_helper)); p = strchr(mce_helper, '\n'); if (p)