2
1

0001-linux_usbfs-Fix-parsing-of-descriptors-for-multi-con.patch 2.2 KB

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