usbip: Fix misuse of strncpy()
authorBen Hutchings <ben@decadent.org.uk>
Fri, 20 Jul 2018 00:30:24 +0000 (01:30 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Wed, 21 Aug 2019 12:48:11 +0000 (13:48 +0100)
commitcf8a33a21b23cf4542fd467dc20c173157a90edc
treef2b9ea26554ed3ab05df20eae0d2185647531e56
parentb27ae7f26d3ae290ddead8447067265fa4cccbf6
usbip: Fix misuse of strncpy()

gcc 8 reports:

usbip_device_driver.c: In function ‘read_usb_vudc_device’:
usbip_device_driver.c:106:2: error: ‘strncpy’ specified bound 256 equals destination size [-Werror=stringop-truncation]
  strncpy(dev->path, path, SYSFS_PATH_MAX);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
usbip_device_driver.c:125:2: error: ‘strncpy’ specified bound 32 equals destination size [-Werror=stringop-truncation]
  strncpy(dev->busid, name, SYSFS_BUS_ID_SIZE);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I'm not convinced it makes sense to truncate the copied strings here,
but since we're already doing so let's ensure they're still null-
terminated.  We can't easily use strlcpy() here, so use snprintf().

usbip_common.c has the same problem.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name usbip-fix-misuse-of-strncpy.patch
tools/usb/usbip/libsrc/usbip_common.c
tools/usb/usbip/libsrc/usbip_device_driver.c