From patchwork Sat Jul 21 02:12:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 10538575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 030AC6029B for ; Sat, 21 Jul 2018 02:12:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCA0A294FD for ; Sat, 21 Jul 2018 02:12:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C04CC29508; Sat, 21 Jul 2018 02:12:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD98C294FD for ; Sat, 21 Jul 2018 02:12:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727333AbeGUDDa (ORCPT ); Fri, 20 Jul 2018 23:03:30 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:39790 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725139AbeGUDD3 (ORCPT ); Fri, 20 Jul 2018 23:03:29 -0400 Received: from ben by shadbolt.decadent.org.uk with local (Exim 4.84_2) (envelope-from ) id 1fghNo-0002l2-HK; Sat, 21 Jul 2018 03:12:32 +0100 Date: Sat, 21 Jul 2018 03:12:32 +0100 From: Ben Hutchings To: Valentina Manea , Shuah Khan Cc: linux-usb@vger.kernel.org Message-ID: <20180721021232.GR14131@decadent.org.uk> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: ben@decadent.org.uk Subject: [PATCH] usbip: Fix misuse of strncpy() X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on shadbolt.decadent.org.uk) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: stable@vger.kernel.org --- tools/usb/usbip/libsrc/usbip_common.c | 4 ++-- tools/usb/usbip/libsrc/usbip_device_driver.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) --- a/tools/usb/usbip/libsrc/usbip_common.c +++ b/tools/usb/usbip/libsrc/usbip_common.c @@ -226,8 +226,8 @@ int read_usb_device(struct udev_device * 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); + snprintf(udev->path, SYSFS_PATH_MAX, "%s", path); + snprintf(udev->busid, SYSFS_BUS_ID_SIZE, "%s", name); sscanf(name, "%u-%u", &busnum, &devnum); udev->busnum = busnum; --- a/tools/usb/usbip/libsrc/usbip_device_driver.c +++ b/tools/usb/usbip/libsrc/usbip_device_driver.c @@ -103,7 +103,7 @@ int read_usb_vudc_device(struct udev_dev copy_descr_attr16(dev, &descr, idProduct); copy_descr_attr16(dev, &descr, bcdDevice); - strncpy(dev->path, path, SYSFS_PATH_MAX); + snprintf(dev->path, SYSFS_PATH_MAX, "%s", path); dev->speed = USB_SPEED_UNKNOWN; speed = udev_device_get_sysattr_value(sdev, "current_speed"); @@ -122,7 +122,7 @@ int read_usb_vudc_device(struct udev_dev dev->busnum = 0; name = udev_device_get_sysname(plat); - strncpy(dev->busid, name, SYSFS_BUS_ID_SIZE); + snprintf(dev->busid, SYSFS_BUS_ID_SIZE, "%s", name); return 0; err: fclose(fd);