mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Juan Zea <juan.zea@qindel.com>
To: shuah@kernel.org
Cc: linux-usb@vger.kernel.org,
	Valentina Manea <valentina.manea.m@gmail.com>,
	linux-kernel@vger.kernel.org,
	Shuah Khan <shuahkh@osg.samsung.com>
Subject: Re: [PATCH] usbip: fix usbip bind writing random string after command in match_busid
Date: Thu, 14 Dec 2017 11:23:39 +0100 (CET)	[thread overview]
Message-ID: <1372575371.1424549.1513247019662.JavaMail.zimbra@qindel.com> (raw)
In-Reply-To: <7eb8f072-c4fe-92c9-a7ad-dda390b5f9db@kernel.org>

> 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

  reply	other threads:[~2017-12-14 10:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <204103862.1370220.1513160163538.JavaMail.zimbra@qindel.com>
2017-12-13 11:07 ` Juan Zea
2017-12-13 17:42   ` Shuah Khan
2017-12-14 10:23     ` Juan Zea [this message]
2017-12-14 20:14       ` Shuah Khan
2017-12-15  9:21         ` Juan Zea
2017-12-15 17:39           ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1372575371.1424549.1513247019662.JavaMail.zimbra@qindel.com \
    --to=juan.zea@qindel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=shuahkh@osg.samsung.com \
    --cc=valentina.manea.m@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome