1From 623e2a995d156e115c91f56a3ec691bdc333df8b Mon Sep 17 00:00:00 2001 2From: Chris Dickens <christopher.a.dickens@gmail.com> 3Date: Sun, 13 Dec 2020 15:49:19 -0800 4Subject: [PATCH 1/1] linux_usbfs: Fix parsing of descriptors for 5 multi-configuration devices 6 7Commit e2be556bd2 ("linux_usbfs: Parse config descriptors during device 8initialization") introduced a regression for devices with multiple 9configurations. The logic that verifies the reported length of the 10configuration descriptors failed to count the length of the 11configuration descriptor itself and would truncate the actual length by 129 bytes, leading to a parsing error for subsequent descriptors. 13 14Closes #825 15 16Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com> 17(cherry picked from commit f6d2cb561402c3b6d3627c0eb89e009b503d9067) 18Signed-off-by: John Keeping <john@metanate.com> 19--- 20 libusb/os/linux_usbfs.c | 12 ++++++++---- 21 1 file changed, 8 insertions(+), 4 deletions(-) 22 23diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c 24index fb2ed53..4d2dc8d 100644 25--- a/libusb/os/linux_usbfs.c 26+++ b/libusb/os/linux_usbfs.c 27@@ -641,7 +641,12 @@ static int seek_to_next_config(struct libusb_context *ctx, 28 uint8_t *buffer, size_t len) 29 { 30 struct usbi_descriptor_header *header; 31- int offset = 0; 32+ int offset; 33+ 34+ /* Start seeking past the config descriptor */ 35+ offset = LIBUSB_DT_CONFIG_SIZE; 36+ buffer += LIBUSB_DT_CONFIG_SIZE; 37+ len -= LIBUSB_DT_CONFIG_SIZE; 38 39 while (len > 0) { 40 if (len < 2) { 41@@ -718,7 +723,7 @@ static int parse_config_descriptors(struct libusb_device *dev) 42 } 43 44 if (priv->sysfs_dir) { 45- /* 46+ /* 47 * In sysfs wTotalLength is ignored, instead the kernel returns a 48 * config descriptor with verified bLength fields, with descriptors 49 * with an invalid bLength removed. 50@@ -727,8 +732,7 @@ static int parse_config_descriptors(struct libusb_device *dev) 51 int offset; 52 53 if (num_configs > 1 && idx < num_configs - 1) { 54- offset = seek_to_next_config(ctx, buffer + LIBUSB_DT_CONFIG_SIZE, 55- remaining - LIBUSB_DT_CONFIG_SIZE); 56+ offset = seek_to_next_config(ctx, buffer, remaining); 57 if (offset < 0) 58 return offset; 59 sysfs_config_len = (uint16_t)offset; 60-- 612.30.1 62 63