diff options
author | Hans de Goede <hdegoede@redhat.com> | 2013-05-23 14:40:05 +0200 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2013-05-24 13:58:37 +0200 |
commit | bbe25fac47c2dfd2d50a2c3a1b0ed96473d8dc1c (patch) | |
tree | 946cd028c7228791db4631488eb23a3c62636ab9 /libusb/descriptor.c | |
parent | af06916bed2c7eb3b1a1a144348ebc7478097604 (diff) | |
download | libusb-bbe25fac47c2dfd2d50a2c3a1b0ed96473d8dc1c.tar.gz |
all: Make usbi_os_backend.get_[active_]config_descriptor return len
Since commit 5e479f1821d3294fb1cc70c5867c69eca2551de7:
"Core: Avoid short read failures on broken descriptors"
usbi_os_backend.get_[active_]config_descriptor no longer return on error
(under Linux) when returning less bytes then requested. But
libusb_get_[active_]config_descriptor still not only requests wTotalLength
bytes, but also blindly assumes that on success it has gotten wTotalLength
bytes.
This patch fixes this, it changes all usbi_os_backend.get_*config_descriptor
implementations to return the actual length on success and uses this value as
the descriptor size in parse_configuration().
Note that the linux and wince backends were already returning the actual
length and thus are not touched.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'libusb/descriptor.c')
-rw-r--r-- | libusb/descriptor.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/libusb/descriptor.c b/libusb/descriptor.c index 9047352..74d3365 100644 --- a/libusb/descriptor.c +++ b/libusb/descriptor.c @@ -338,17 +338,15 @@ static void clear_configuration(struct libusb_config_descriptor *config) static int parse_configuration(struct libusb_context *ctx, struct libusb_config_descriptor *config, unsigned char *buffer, - int host_endian) + int size, int host_endian) { int i; int r; - int size; size_t tmp; struct usb_descriptor_header header; struct libusb_interface *usb_interface; usbi_parse_descriptor(buffer, "bbwbbbbb", config, host_endian); - size = config->wTotalLength; if (config->bNumInterfaces > USB_MAXINTERFACES) { usbi_err(ctx, "too many interfaces (%d)", config->bNumInterfaces); @@ -521,7 +519,7 @@ int API_EXPORTED libusb_get_active_config_descriptor(libusb_device *dev, if (r < 0) goto err; - r = parse_configuration(dev->ctx, _config, buf, host_endian); + r = parse_configuration(dev->ctx, _config, buf, r, host_endian); if (r < 0) { usbi_err(dev->ctx, "parse_configuration failed with error %d", r); goto err; @@ -591,7 +589,7 @@ int API_EXPORTED libusb_get_config_descriptor(libusb_device *dev, if (r < 0) goto err; - r = parse_configuration(dev->ctx, _config, buf, host_endian); + r = parse_configuration(dev->ctx, _config, buf, r, host_endian); if (r < 0) { usbi_err(dev->ctx, "parse_configuration failed with error %d", r); goto err; |