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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 9, 2022 at 9:45 AM <yang.yang29@xxxxxxxxxx> wrote:
>
> From: Xu Panda <xu.panda@xxxxxxxxxx>
>
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL terminated strings.

...

> +       strscpy(arg, val, strnchrnul(val, ACTION_LEN - 1, '\n') - val + 1);

Instead of  -1 +1 you should simply use the sizeof(arg) as I mentioned.

       strscpy(arg, val, strnchrnul(val, sizeof(arg), '\n') - val);

The returned pointer by strnchrnul() either points to the '\n' or to
'\0' and when we subtract pointer to the start we will get the exact
length of the string. In case it equals ACTION_LEN the last character
will be replaced by '\0'.

Where am I mistaken?

-- 
With Best Regards,
Andy Shevchenko



[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux