lkml.org 
[lkml]   [2022]   [Dec]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH linux-next] x86/platform/uv: use strscpy to instead of strncpy()
On Sat, Dec 3, 2022 at 2:15 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Sat, Dec 3, 2022 at 8:24 AM <yang.yang29@zte.com.cn> wrote:

...

> > /* (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);

Or even drop p completely

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

--
With Best Regards,
Andy Shevchenko

\
 
 \ /
  Last update: 2022-12-03 13:20    [W:0.030 / U:1.768 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site