usbip: Fix misuse of strncpy()
authorBen Hutchings <ben@decadent.org.uk>
Fri, 20 Jul 2018 00:30:24 +0000 (01:30 +0100)
committerSalvatore Bonaccorso <carnil@debian.org>
Sat, 18 Aug 2018 12:02:58 +0000 (13:02 +0100)
commit8c73abe564dbf016a7db8b00638f98510da67c46
tree7b2c048ed49a80c2f3e0587e7fe2dd8de47c799e
parent952e85cc62367dd1a14d16241fafeebbc91f1dce
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