x86/mce/dev-mcelog: use strscpy() to instead of strncpy()
authorXu Panda <xu.panda@zte.com.cn>
Sat, 3 Dec 2022 06:19:32 +0000 (14:19 +0800)
committerIngo Molnar <mingo@kernel.org>
Sat, 7 Jan 2023 10:47:35 +0000 (11:47 +0100)
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 <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Link: https://lore.kernel.org/r/202212031419324523731@zte.com.cn
arch/x86/kernel/cpu/mce/dev-mcelog.c

index 100fbee..a05ac07 100644 (file)
@@ -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)