From 24b63efe460b56559437c44a21f9d4b034e8dca8 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Wed, 22 May 2013 14:52:37 +0200 Subject: [PATCH] linux: Clear descriptor buffer before read when using usbfs In usbfs the config descriptors are config.wTotalLength bytes apart, but the device may actually return a shorter descriptor then advertised, in this case the kernel will simply skip over any bytes read which the device did not actually return. Note the kernel will *not* return 0 data, it will simply leave the memory passed in to the read call as is. Therefor this patch clears the buffer before calling read, to ensure that the non existing parts of the descriptors are always properly zero-ed. Signed-off-by: Hans de Goede --- libusb/os/linux_usbfs.c | 5 +++++ libusb/version_nano.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index dd11b18..9c07549 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -998,6 +998,11 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum, close(fd); return LIBUSB_ERROR_NO_MEM; } + /* usbfs has holes in the file */ + if (!sysfs_has_descriptors) { + memset(priv->descriptors + priv->descriptors_len, + 0, descriptors_size - priv->descriptors_len); + } r = read(fd, priv->descriptors + priv->descriptors_len, descriptors_size - priv->descriptors_len); if (r < 0) { diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 079ba39..044b0da 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10702 +#define LIBUSB_NANO 10703 -- 2.7.4