Re: [PATCH 1/4] leds: netdev trigger: use memcpy in device_name_store
From: Uwe Kleine-König
Date: Thu Mar 14 2019 - 06:04:21 EST
On Thu, Mar 14, 2019 at 10:57:14AM +0100, Rasmus Villemoes wrote:
> On 14/03/2019 10.29, Uwe Kleine-König wrote:
> > Hello,
> >
> > On Wed, Mar 13, 2019 at 09:26:12PM +0100, Rasmus Villemoes wrote:
> >> --- a/drivers/leds/trigger/ledtrig-netdev.c
> >> +++ b/drivers/leds/trigger/ledtrig-netdev.c
> >> @@ -122,7 +122,8 @@ static ssize_t device_name_store(struct device *dev,
> >> trigger_data->net_dev = NULL;
> >> }
> >>
> >> - strncpy(trigger_data->device_name, buf, size);
> >> + memcpy(trigger_data->device_name, buf, size);
> >> + trigger_data->device_name[size] = '\0';
> >
> > This is open-coding
> >
> > strlcpy(trigger_data->device_name, buf, size);
>
> No. size here is the number of bytes userspace wrote, which never (well,
> almost never, they could do something odd) contain a nul byte. Passing
> that as size to strlcpy would guarantee that we chopped off the last
> character from the user input.
You're right here, strlcpy isn't a replacement here. I withdraw my
suggestion.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |