Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752642AbdLNUOa (ORCPT ); Thu, 14 Dec 2017 15:14:30 -0500 Received: from osg.samsung.com ([64.30.133.232]:42241 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752259AbdLNUO1 (ORCPT ); Thu, 14 Dec 2017 15:14:27 -0500 Subject: Re: [PATCH] usbip: fix usbip bind writing random string after command in match_busid To: Juan Zea , shuah@kernel.org Cc: linux-usb@vger.kernel.org, Valentina Manea , linux-kernel@vger.kernel.org, Shuah Khan References: <204103862.1370220.1513160163538.JavaMail.zimbra@qindel.com> <473236275.1374013.1513163260837.JavaMail.zimbra@qindel.com> <7eb8f072-c4fe-92c9-a7ad-dda390b5f9db@kernel.org> <1372575371.1424549.1513247019662.JavaMail.zimbra@qindel.com> From: Shuah Khan Message-ID: <3e547346-a2ec-b8b2-2d4a-25a75b068e08@osg.samsung.com> Date: Thu, 14 Dec 2017 13:14:24 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <1372575371.1424549.1513247019662.JavaMail.zimbra@qindel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1621 Lines: 47 On 12/14/2017 03:23 AM, Juan Zea wrote: >> Why not use the return value from snprintf() for length, instead of calling > strlen(command)? > > Yes, that makes sense. Something like this? Yes > > 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 > thanks, -- Shuah