Skip to content

Commit 9093464

Browse files
Villemoesjacek-anaszewski
authored andcommitted
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: 06f502f ("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>
1 parent 0aab8e4 commit 9093464

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/leds/trigger/ledtrig-netdev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ static ssize_t device_name_store(struct device *dev,
122122
trigger_data->net_dev = NULL;
123123
}
124124

125-
strncpy(trigger_data->device_name, buf, size);
125+
memcpy(trigger_data->device_name, buf, size);
126+
trigger_data->device_name[size] = 0;
126127
if (size > 0 && trigger_data->device_name[size - 1] == '\n')
127128
trigger_data->device_name[size - 1] = 0;
128129

0 commit comments

Comments
 (0)