]> git.baikalelectronics.ru Git - kernel.git/commit
leds: trigger: netdev: use memcpy in device_name_store
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Thu, 14 Mar 2019 14:06:14 +0000 (15:06 +0100)
committerJacek Anaszewski <jacek.anaszewski@gmail.com>
Sat, 30 Mar 2019 18:09:32 +0000 (19:09 +0100)
commita8fa815ebafd54852400421f9f92c65996bef622
treea00e6c4fe49136d7c79c2b294e441e78eb121f92
parentd54f9e60fac28df2968d0841d6c8b668bb654383
leds: trigger: netdev: use memcpy in device_name_store

If userspace doesn't end the input with a newline (which can easily
happen if the write happens from a C program that does write(fd,
iface, strlen(iface))), we may end up including garbage from a
previous, longer value in the device_name. For example

# cat device_name

# printf 'eth12' > device_name
# cat device_name
eth12
# printf 'eth3' > device_name
# cat device_name
eth32

I highly doubt anybody is relying on this behaviour, so switch to
simply copying the bytes (we've already checked that size is <
IFNAMSIZ) and unconditionally zero-terminate it; of course, we also
still have to strip a trailing newline.

This is also preparation for future patches.

Fixes: fafa8a62c607 ("leds: trigger: Introduce a NETDEV trigger")
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
drivers/leds/trigger/ledtrig-netdev.c