From 25ca1a3f125abe64c5967890babbef5ec3e2079b Mon Sep 17 00:00:00 2001 From: Jonathan Dieter Date: Mon, 27 Feb 2017 09:18:30 +0200 Subject: [PATCH] Fix build failures with GCC 7 Signed-off-by: Jonathan Dieter --- 0001-usbip-Fix-format-overflow.patch | 106 ++++++++++++++++++ ...bip-Fix-implicit-fallthrough-warning.patch | 33 ++++++ usbip.spec | 12 +- 3 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 0001-usbip-Fix-format-overflow.patch create mode 100644 0002-usbip-Fix-implicit-fallthrough-warning.patch diff --git a/0001-usbip-Fix-format-overflow.patch b/0001-usbip-Fix-format-overflow.patch new file mode 100644 index 0000000..67ce071 --- /dev/null +++ b/0001-usbip-Fix-format-overflow.patch @@ -0,0 +1,106 @@ +From ad4d8dccc457e3b45b47fd5c5fdebfcf0171aa5e Mon Sep 17 00:00:00 2001 +From: Jonathan Dieter +Date: Wed, 22 Feb 2017 20:03:06 +0200 +Subject: [PATCH] usbip: Fix-format-overflow + +The usbip userspace tools call sprintf()/snprintf() and don't check for +the return value which can lead the paths to overflow, truncating the +final file in the path. + +More urgently, GCC 7 now warns that these aren't checked with +-Wformat-overflow, and with -Werror enabled in configure.ac, that makes +these tools unbuildable. + +This patch fixes these problems by replacing sprintf() with snprintf() in +one place and adding checks for the return value of snprintf(). + +Reviewed-by: Peter Senna Tschudin +Signed-off-by: Jonathan Dieter +--- + tools/usb/usbip/libsrc/usbip_common.c | 8 +++++++- + tools/usb/usbip/libsrc/usbip_host_common.c | 28 +++++++++++++++++++++++----- + 2 files changed, 30 insertions(+), 6 deletions(-) + +diff --git a/tools/usb/usbip/libsrc/usbip_common.c b/tools/usb/usbip/libsrc/usbip_common.c +index ac73710..66017d7 100644 +--- a/tools/usb/usbip/libsrc/usbip_common.c ++++ b/tools/usb/usbip/libsrc/usbip_common.c +@@ -215,9 +215,15 @@ int read_usb_interface(struct usbip_usb_device *udev, int i, + struct usbip_usb_interface *uinf) + { + char busid[SYSFS_BUS_ID_SIZE]; ++ int size; + struct udev_device *sif; + +- sprintf(busid, "%s:%d.%d", udev->busid, udev->bConfigurationValue, i); ++ size = snprintf(busid, sizeof(busid), "%s:%d.%d", ++ udev->busid, udev->bConfigurationValue, i); ++ if (size < 0 || (unsigned int)size >= sizeof(busid)) { ++ err("busid length %i >= %lu or < 0", size, sizeof(busid)); ++ return -1; ++ } + + sif = udev_device_new_from_subsystem_sysname(udev_context, "usb", busid); + if (!sif) { +diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c b/tools/usb/usbip/libsrc/usbip_host_common.c +index 9d41522..6fb91d9 100644 +--- a/tools/usb/usbip/libsrc/usbip_host_common.c ++++ b/tools/usb/usbip/libsrc/usbip_host_common.c +@@ -40,13 +40,20 @@ struct udev *udev_context; + static int32_t read_attr_usbip_status(struct usbip_usb_device *udev) + { + char status_attr_path[SYSFS_PATH_MAX]; ++ int size; + int fd; + int length; + char status; + int value = 0; + +- snprintf(status_attr_path, SYSFS_PATH_MAX, "%s/usbip_status", +- udev->path); ++ size = snprintf(status_attr_path, sizeof(status_attr_path), ++ "%s/usbip_status", udev->path); ++ if (size < 0 || (unsigned int)size >= sizeof(status_attr_path)) { ++ err("usbip_status path length %i >= %lu or < 0", size, ++ sizeof(status_attr_path)); ++ return -1; ++ } ++ + + fd = open(status_attr_path, O_RDONLY); + if (fd < 0) { +@@ -218,6 +225,7 @@ int usbip_export_device(struct usbip_exported_device *edev, int sockfd) + { + char attr_name[] = "usbip_sockfd"; + char sockfd_attr_path[SYSFS_PATH_MAX]; ++ int size; + char sockfd_buff[30]; + int ret; + +@@ -237,10 +245,20 @@ int usbip_export_device(struct usbip_exported_device *edev, int sockfd) + } + + /* only the first interface is true */ +- snprintf(sockfd_attr_path, sizeof(sockfd_attr_path), "%s/%s", +- edev->udev.path, attr_name); ++ size = snprintf(sockfd_attr_path, sizeof(sockfd_attr_path), "%s/%s", ++ edev->udev.path, attr_name); ++ if (size < 0 || (unsigned int)size >= sizeof(sockfd_attr_path)) { ++ err("exported device path length %i >= %lu or < 0", size, ++ sizeof(sockfd_attr_path)); ++ return -1; ++ } + +- snprintf(sockfd_buff, sizeof(sockfd_buff), "%d\n", sockfd); ++ size = snprintf(sockfd_buff, sizeof(sockfd_buff), "%d\n", sockfd); ++ if (size < 0 || (unsigned int)size >= sizeof(sockfd_buff)) { ++ err("socket length %i >= %lu or < 0", size, ++ sizeof(sockfd_buff)); ++ return -1; ++ } + + ret = write_sysfs_attribute(sockfd_attr_path, sockfd_buff, + strlen(sockfd_buff)); +-- +2.9.3 + diff --git a/0002-usbip-Fix-implicit-fallthrough-warning.patch b/0002-usbip-Fix-implicit-fallthrough-warning.patch new file mode 100644 index 0000000..5adceba --- /dev/null +++ b/0002-usbip-Fix-implicit-fallthrough-warning.patch @@ -0,0 +1,33 @@ +From 1d33ad30f2bad7d2c3f431b676e57f092596840c Mon Sep 17 00:00:00 2001 +From: Jonathan Dieter +Date: Tue, 21 Feb 2017 19:41:35 +0200 +Subject: [PATCH v2 2/2] usbip: Fix implicit fallthrough warning + +GCC 7 now warns when switch statements fall through implicitly, and with +-Werror enabled in configure.ac, that makes these tools unbuildable. + +We fix this by notifying the compiler that this particular case statement +is meant to fall through. + +Reviewed-by: Peter Senna Tschudin +Signed-off-by: Jonathan Dieter +--- + tools/usb/usbip/src/usbip.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/tools/usb/usbip/src/usbip.c b/tools/usb/usbip/src/usbip.c +index d7599d9..73d8eee 100644 +--- a/tools/usb/usbip/src/usbip.c ++++ b/tools/usb/usbip/src/usbip.c +@@ -176,6 +176,8 @@ int main(int argc, char *argv[]) + break; + case '?': + printf("usbip: invalid option\n"); ++ /* Terminate after printing error */ ++ /* FALLTHRU */ + default: + usbip_usage(); + goto out; +-- +2.9.3 + diff --git a/usbip.spec b/usbip.spec index d5a0ba1..f71dc26 100644 --- a/usbip.spec +++ b/usbip.spec @@ -5,7 +5,7 @@ License: GPLv2+ Summary: USB/IP user-space Group: System Environment/Daemons Version: 4.9.9 -Release: 1%{?dist} +Release: 2%{?dist} #Source: https://www.kernel.org/pub/linux/kernel/v3.x/linux-%%{version}.tar.xz # In the interests of keeping the source rpm from being ridiculously large, # download the Linux kernel from above and run `extract_usbip.sh ` @@ -15,6 +15,11 @@ Source: usbip-%{version}.tar.xz Source1: usbip-server.service Source2: usbip-client.service Source99: extract_usbip.sh +# The following patches have been submitted to the LKML (see the thread +# starting at https://www.spinics.net/lists/kernel/msg2448891.html) and are +# still in the process of being reviewed. +Patch1: 0001-usbip-Fix-format-overflow.patch +Patch2: 0002-usbip-Fix-implicit-fallthrough-warning.patch Requires: kmod(usbip-core.ko) Requires: kmod(usbip-host.ko) Requires: kmod(vhci-hcd.ko) @@ -49,6 +54,8 @@ development %prep %setup -q +%patch1 -p4 +%patch2 -p4 %build ./autogen.sh @@ -87,6 +94,9 @@ install -pm 644 %{SOURCE2} %{buildroot}%{_unitdir} %{_libdir}/*.so %changelog +* Mon Feb 20 2017 Jonathan Dieter - 4.9.9-2 +- Add patches to fix continuing build failures with GCC 7 + * Sun Feb 12 2017 Jonathan Dieter - 4.9.9-1 - Update to 4.9.9 with build fixes