Skip to content

Commit

Permalink
drivers/net/usb: Remove all strcpy() uses
Browse files Browse the repository at this point in the history
strcpy() performs no bounds checking on the destination buffer. This
could result in linear overflows beyond the end of the buffer, leading
to all kinds of misbehaviors. The safe replacement is strscpy().

Signed-off-by: Len Baker <len.baker@gmx.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Len Baker authored and David S. Miller committed Aug 3, 2021
1 parent 9c638ea commit 493c3ca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion drivers/net/usb/ipheth.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ static int ipheth_probe(struct usb_interface *intf,

netdev->netdev_ops = &ipheth_netdev_ops;
netdev->watchdog_timeo = IPHETH_TX_TIMEOUT;
strcpy(netdev->name, "eth%d");
strscpy(netdev->name, "eth%d", sizeof(netdev->name));

dev = netdev_priv(netdev);
dev->udev = udev;
Expand Down
8 changes: 4 additions & 4 deletions drivers/net/usb/usbnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
dev->interrupt_count = 0;

dev->net = net;
strcpy (net->name, "usb%d");
strscpy(net->name, "usb%d", sizeof(net->name));
memcpy (net->dev_addr, node_id, sizeof node_id);

/* rx and tx sides can use different message sizes;
Expand All @@ -1752,13 +1752,13 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
if ((dev->driver_info->flags & FLAG_ETHER) != 0 &&
((dev->driver_info->flags & FLAG_POINTTOPOINT) == 0 ||
(net->dev_addr [0] & 0x02) == 0))
strcpy (net->name, "eth%d");
strscpy(net->name, "eth%d", sizeof(net->name));
/* WLAN devices should always be named "wlan%d" */
if ((dev->driver_info->flags & FLAG_WLAN) != 0)
strcpy(net->name, "wlan%d");
strscpy(net->name, "wlan%d", sizeof(net->name));
/* WWAN devices should always be named "wwan%d" */
if ((dev->driver_info->flags & FLAG_WWAN) != 0)
strcpy(net->name, "wwan%d");
strscpy(net->name, "wwan%d", sizeof(net->name));

/* devices that cannot do ARP */
if ((dev->driver_info->flags & FLAG_NOARP) != 0)
Expand Down

0 comments on commit 493c3ca

Please sign in to comment.