Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usbip: fix usbip bind writing random string after command in match_busid

usbip bind writes commands followed by random string when writing to
match_busid attribute in sysfs, caused by using full variable size
instead of string length.

Signed-off-by: Juan Zea <juan.zea@qindel.com>
Acked-by: Shuah Khan <shuahkh@osg.samsung.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Juan Zea and committed by
Greg Kroah-Hartman
544c4605 10c90120

+6 -3
+6 -3
tools/usb/usbip/src/utils.c
··· 30 30 char command[SYSFS_BUS_ID_SIZE + 4]; 31 31 char match_busid_attr_path[SYSFS_PATH_MAX]; 32 32 int rc; 33 + int cmd_size; 33 34 34 35 snprintf(match_busid_attr_path, sizeof(match_busid_attr_path), 35 36 "%s/%s/%s/%s/%s/%s", SYSFS_MNT_PATH, SYSFS_BUS_NAME, ··· 38 37 attr_name); 39 38 40 39 if (add) 41 - snprintf(command, SYSFS_BUS_ID_SIZE + 4, "add %s", busid); 40 + cmd_size = snprintf(command, SYSFS_BUS_ID_SIZE + 4, "add %s", 41 + busid); 42 42 else 43 - snprintf(command, SYSFS_BUS_ID_SIZE + 4, "del %s", busid); 43 + cmd_size = snprintf(command, SYSFS_BUS_ID_SIZE + 4, "del %s", 44 + busid); 44 45 45 46 rc = write_sysfs_attribute(match_busid_attr_path, command, 46 - sizeof(command)); 47 + cmd_size); 47 48 if (rc < 0) { 48 49 dbg("failed to write match_busid: %s", strerror(errno)); 49 50 return -1;