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>
Sun, 7 Oct 2018 20:57:06 +0000 (21:57 +0100)
commitf50ac60ad43fadd185803964587c1b40c5f8a65a
treeba2b3b2e3fd051521b8f130bed85a23f5100997b
parent5b8ea832b439dcaa253c0e419839aafef4499c5f
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