Commit 6389a62f authored by Liu, Changcheng's avatar Liu, Changcheng Committed by Greg Kroah-Hartman

usbip: tools: fix GCC8 warning for strncpy

GCC8 started emitting warning about using strncpy with number of bytes
exactly equal destination size which could lead to non-zero terminated
string being copied. Use "SYSFS_PATH_MAX - 1" & "SYSFS_BUS_ID_SIZE - 1"
as number of bytes to ensure name is always zero-terminated.
Signed-off-by: default avatarChangcheng Liu <changcheng.liu@aliyun.com>
Acked-by: default avatarShuah Khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/20190725132209.GA27590@jerryopenixSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 34d05459
......@@ -226,8 +226,10 @@ int read_usb_device(struct udev_device *sdev, struct usbip_usb_device *udev)
path = udev_device_get_syspath(sdev);
name = udev_device_get_sysname(sdev);
strncpy(udev->path, path, SYSFS_PATH_MAX);
strncpy(udev->busid, name, SYSFS_BUS_ID_SIZE);
strncpy(udev->path, path, SYSFS_PATH_MAX - 1);
udev->path[SYSFS_PATH_MAX - 1] = '\0';
strncpy(udev->busid, name, SYSFS_BUS_ID_SIZE - 1);
udev->busid[SYSFS_BUS_ID_SIZE - 1] = '\0';
sscanf(name, "%u-%u", &busnum, &devnum);
udev->busnum = busnum;
......
......@@ -91,7 +91,8 @@ int read_usb_vudc_device(struct udev_device *sdev, struct usbip_usb_device *dev)
copy_descr_attr16(dev, &descr, idProduct);
copy_descr_attr16(dev, &descr, bcdDevice);
strncpy(dev->path, path, SYSFS_PATH_MAX);
strncpy(dev->path, path, SYSFS_PATH_MAX - 1);
dev->path[SYSFS_PATH_MAX - 1] = '\0';
dev->speed = USB_SPEED_UNKNOWN;
speed = udev_device_get_sysattr_value(sdev, "current_speed");
......@@ -110,7 +111,8 @@ int read_usb_vudc_device(struct udev_device *sdev, struct usbip_usb_device *dev)
dev->busnum = 0;
name = udev_device_get_sysname(plat);
strncpy(dev->busid, name, SYSFS_BUS_ID_SIZE);
strncpy(dev->busid, name, SYSFS_BUS_ID_SIZE - 1);
dev->busid[SYSFS_BUS_ID_SIZE - 1] = '\0';
return 0;
err:
fclose(fd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment