All of lore.kernel.org
 help / color / mirror / Atom feed
* minor bug in usbip tool
@ 2017-12-12 15:04 Juan Zea
  0 siblings, 0 replies; 2+ messages in thread
From: Juan Zea @ 2017-12-12 15:04 UTC (permalink / raw)
  To: linux-usb

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;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* minor bug in usbip tool
@ 2017-12-12 21:20 Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2017-12-12 21:20 UTC (permalink / raw)
  To: Juan Zea; +Cc: linux-usb

On Tue, Dec 12, 2017 at 04:04:27PM +0100, Juan Zea wrote:
> 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:

Thanks for finding this and sending a patch.

But:

> 
> 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;
> 

Can you resend this in a format that we can apply it in?  Please look at
Documentation/SubmittingPatches for how to do this.

thanks,

greg k-h
---
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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-12 21:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-12 15:04 minor bug in usbip tool Juan Zea
2017-12-12 21:20 Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.