]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Skip unexpected descriptors
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 1 Aug 2010 21:08:03 +0000 (23:08 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 1 Aug 2010 21:08:03 +0000 (23:08 +0200)
bus/usb/usb.c
include/grub/usbdesc.h

index a961e0b48a7af048763cab317c60343f2362a66b..b3eaeba0e8844b19d3501a5640e778becd813cdd 100644 (file)
@@ -209,14 +209,23 @@ grub_usb_device_initialize (grub_usb_device_t dev)
        goto fail;
 
       /* Skip the configuration descriptor.  */
-      pos = sizeof (struct grub_usb_desc_config);
+      pos = dev->config[i].descconf->length;
 
       /* Read all interfaces.  */
       for (currif = 0; currif < dev->config[i].descconf->numif; currif++)
        {
+         while (pos < config.totallen
+                && ((struct grub_usb_desc *)&data[pos])->type
+                != GRUB_USB_DESCRIPTOR_INTERFACE)
+           pos += ((struct grub_usb_desc *)&data[pos])->length;
          dev->config[i].interf[currif].descif
            = (struct grub_usb_desc_if *) &data[pos];
-         pos += sizeof (struct grub_usb_desc_if);
+         pos += dev->config[i].interf[currif].descif->length;
+
+         while (pos < config.totallen
+                && ((struct grub_usb_desc *)&data[pos])->type
+                != GRUB_USB_DESCRIPTOR_ENDPOINT)
+           pos += ((struct grub_usb_desc *)&data[pos])->length;
 
          /* Point to the first endpoint.  */
          dev->config[i].interf[currif].descendp
index 2f711d7550c6ad9d257594883a68e9ea6dad92ea..84b723a62dcb3c2c553ec7a9cf4bf73b3e311997 100644 (file)
@@ -31,6 +31,12 @@ typedef enum {
   GRUB_USB_DESCRIPTOR_HUB = 0x29
 } grub_usb_descriptor_t;
 
+struct grub_usb_desc
+{
+  grub_uint8_t length;
+  grub_uint8_t type;
+} __attribute__ ((packed));
+
 struct grub_usb_desc_device
 {
   grub_uint8_t length;