Skip to content

Commit

Permalink
x86/mce/dev-mcelog: use strscpy() to instead of strncpy()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Xu Panda authored and Ingo Molnar committed Jan 7, 2023
1 parent bd4edba commit 7ddf005
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions arch/x86/kernel/cpu/mce/dev-mcelog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7ddf005

Please sign in to comment.