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