Disallow libusb_get_string_descriptor_ascii() with index 0
authorKonrad Rzepecki <hannibal@astral.lodz.pl>
Sat, 13 Nov 2010 13:09:22 +0000 (14:09 +0100)
committerPeter Stuge <peter@stuge.se>
Mon, 22 Nov 2010 04:46:40 +0000 (05:46 +0100)
String descriptor 0 is the list of supported language IDs in the device,
which can't have an ASCII representation. Calling the function with
index 0 is thus not really useful. Fixes #43.

libusb/descriptor.c

index f25a8b3..11480e8 100644 (file)
@@ -681,10 +681,17 @@ int API_EXPORTED libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
        uint16_t langid;
 
        /* Asking for the zero'th index is special - it returns a string
-        * descriptor that contains all the language IDs supported by the device.
-        * Typically there aren't many - often only one. The language IDs are 16
-        * bit numbers, and they start at the third byte in the descriptor. See
-        * USB 2.0 specification section 9.6.7 for more information. */
+        * descriptor that contains all the language IDs supported by the
+        * device. Typically there aren't many - often only one. Language
+        * IDs are 16 bit numbers, and they start at the third byte in the
+        * descriptor. There's also no point in trying to read descriptor 0
+        * with this function. See USB 2.0 specification section 9.6.7 for
+        * more information.
+        */
+
+       if (desc_index == 0)
+               return LIBUSB_ERROR_INVALID_PARAM;
+
        r = libusb_get_string_descriptor(dev, 0, 0, tbuf, sizeof(tbuf));
        if (r < 0)
                return r;