linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Juan Zea <juan.zea@qindel.com>
To: linux-usb@vger.kernel.org
Subject: minor bug in usbip tool
Date: Tue, 12 Dec 2017 16:04:27 +0100 (CET)	[thread overview]
Message-ID: <1921458196.1334657.1513091067491.JavaMail.zimbra@qindel.com> (raw)

Hi,

 I've being taking a deep look at the code in the usbip tool and found this small bug at https://github.com/torvalds/linux/blob/master/tools/usb/usbip/src/utils.c :

44         rc = write_sysfs_attribute(match_busid_attr_path, command,
45                                    sizeof(command));
                                            ^
 
Using sizeof instead of strlen in this line, leads to the following situation as seen by a strace:
strace -s100000 /usr/local/sbin/usbip bind -b 1-1.3
.
.
open("/sys/bus/usb/drivers/usbip-host/match_busid", O_WRONLY) = 3
write(3, "add 1-1.3\0@\0\0\0\0\0unbind\0\0\0\0\0\0\0\0\0\0/sys", 36) = 36
close(3)      
.
.

The string line should be "add 1-1.3" alone, but well, it works, so no doubt nobody noticed before.

Thought it is worth reporting anyway. Here's the patch:



Regards,
Juan Zea

Juan Antonio Zea Herranz 
Proyectos y consultoría | Qindel Group 
E: juan.zea@qindel.com 
T: +34 91 766 24 21 
M: +34 637 74 63 09 
W: qindel.com
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

diff --git a/tools/usb/usbip/src/utils.c b/tools/usb/usbip/src/utils.c
index 2b3d6d2..ea1a1af 100644
--- a/tools/usb/usbip/src/utils.c
+++ b/tools/usb/usbip/src/utils.c
@@ -42,7 +42,7 @@ int modify_match_busid(char *busid, int add)
                snprintf(command, SYSFS_BUS_ID_SIZE + 4, "del %s", busid);
 
        rc = write_sysfs_attribute(match_busid_attr_path, command,
-                                  sizeof(command));
+                                  strlen(command));
        if (rc < 0) {
                dbg("failed to write match_busid: %s", strerror(errno));
                return -1;

             reply	other threads:[~2017-12-12 15:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-12 15:04 Juan Zea [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-12-12 21:20 minor bug in usbip tool Greg KH

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=1921458196.1334657.1513091067491.JavaMail.zimbra@qindel.com \
    --to=juan.zea@qindel.com \
    --cc=linux-usb@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).