Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751127AbdLNKXu (ORCPT ); Thu, 14 Dec 2017 05:23:50 -0500 Received: from smtp.qindel.com ([89.140.90.34]:35099 "EHLO thor.qindel.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750737AbdLNKXs (ORCPT ); Thu, 14 Dec 2017 05:23:48 -0500 Date: Thu, 14 Dec 2017 11:23:39 +0100 (CET) From: Juan Zea To: shuah@kernel.org Cc: linux-usb@vger.kernel.org, Valentina Manea , linux-kernel@vger.kernel.org, Shuah Khan Message-ID: <1372575371.1424549.1513247019662.JavaMail.zimbra@qindel.com> In-Reply-To: <7eb8f072-c4fe-92c9-a7ad-dda390b5f9db@kernel.org> References: <204103862.1370220.1513160163538.JavaMail.zimbra@qindel.com> <473236275.1374013.1513163260837.JavaMail.zimbra@qindel.com> <7eb8f072-c4fe-92c9-a7ad-dda390b5f9db@kernel.org> Subject: Re: [PATCH] usbip: fix usbip bind writing random string after command in match_busid MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [172.26.0.51] X-Mailer: Zimbra 8.0.6_GA_5922 (ZimbraWebClient - FF57 (Linux)/8.0.6_GA_5922) Thread-Topic: usbip: fix usbip bind writing random string after command in match_busid Thread-Index: w69HZHthU4zcdxy/tUpmpSagCqZbiw== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1477 Lines: 39 > Why not use the return value from snprintf() for length, instead of calling strlen(command)? Yes, that makes sense. Something like this? diff --git a/tools/usb/usbip/src/utils.c b/tools/usb/usbip/src/utils.c index 2b3d6d2..3d7b42e 100644 --- a/tools/usb/usbip/src/utils.c +++ b/tools/usb/usbip/src/utils.c @@ -30,6 +30,7 @@ int modify_match_busid(char *busid, int add) char command[SYSFS_BUS_ID_SIZE + 4]; char match_busid_attr_path[SYSFS_PATH_MAX]; int rc; + int cmd_size; snprintf(match_busid_attr_path, sizeof(match_busid_attr_path), "%s/%s/%s/%s/%s/%s", SYSFS_MNT_PATH, SYSFS_BUS_NAME, @@ -37,12 +38,14 @@ int modify_match_busid(char *busid, int add) attr_name); if (add) - snprintf(command, SYSFS_BUS_ID_SIZE + 4, "add %s", busid); + cmd_size = snprintf(command, SYSFS_BUS_ID_SIZE + 4, "add %s", + busid); else - snprintf(command, SYSFS_BUS_ID_SIZE + 4, "del %s", busid); + cmd_size = snprintf(command, SYSFS_BUS_ID_SIZE + 4, "del %s", + busid); rc = write_sysfs_attribute(match_busid_attr_path, command, - sizeof(command)); + cmd_size); if (rc < 0) { dbg("failed to write match_busid: %s", strerror(errno)); return -1; Regards, Juan