Re: [PATCH] devlink/param: replace deprecated strcpy() with strscpy()
From: David Laight
Date: Thu May 07 2026 - 17:10:43 EST
On Thu, 7 May 2026 07:52:34 -0700
Jakub Kicinski <kuba@xxxxxxxxxx> wrote:
> On Thu, 7 May 2026 09:04:45 +0100 David Laight wrote:
> > > case DEVLINK_PARAM_TYPE_STRING:
> > > - len = strnlen(nla_data(param_data), nla_len(param_data));
> > > - if (len == nla_len(param_data) ||
> > > - len >= __DEVLINK_PARAM_MAX_STRING_VALUE)
> > > + len = strscpy(value->vstr, nla_data(param_data));
> > > + if (len < 0)
> > > return -EINVAL;
> > > - strcpy(value->vstr, nla_data(param_data));
> >
> > The only sensible thing here is to replace the strcpy() with:
> > memcpy(value->vstr, nla_data(param_data), len + 1);
>
> That'd probably be a good move, to avoid getting the broken strscpy()
> conversion submissions. Care to send a patch?
I'll lob one in soon.
I'm working my way through a compile that errors strcpy() except for
constant strings into arrays (ie the safe ones).
Why is it that the worst examples is in the 'secerity code' :-)
-- David