Re: [PATCH linux-next] x86/platform/uv: use strscpy to instead of strncpy()

From: Andy Shevchenko
Date: Sat Dec 03 2022 - 07:16:23 EST


On Sat, Dec 3, 2022 at 8:24 AM <yang.yang29@xxxxxxxxxx> wrote:

> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL terminated strings.

...

> /* (remove possible '\n') */
> - strncpy(arg, val, ACTION_LEN - 1);
> - arg[ACTION_LEN - 1] = '\0';
> + strscpy(arg, val, ACTION_LEN - 1);

Should be ACTION_LEN here, no?

> p = strchr(arg, '\n');
> if (p)
> *p = '\0';

Wouldn't be better to refactor this

p = strnchrnul(val, ACTION_LEN, '\n');
strscpy(arg, val, p - val);

?

--
With Best Regards,
Andy Shevchenko