> I think it's overkill.  Despite what I wrote before, that test patch you 
> sent out yesterday looked pretty good.  Config options and blacklists 
> should be avoided if at all possible, especially for stupid little things 
> like this.
> 
> When the string descriptor routines encounter a result that has both type
> and length equal to 0, cautious scanning seems like a good way to proceed.
> In other words, I like option (C) but not (A) or (B).  And I would leave
> out the part about suggesting an email to the list, since it's not needed
> if no one is maintaining a black/whitelist.

How about this?  I tweaked usb_string_sub while I was there so it only ever
returns even lengths (in the case of an odd length, usb_string used to read
the last, uninitialised character - better to fix this in usb_string_sub).
Now I think about it, the debug message should also print the descriptor index.
If you are happy with this I will make that change and send the patch to Greg.

Ciao,

Duncan.

Index: local-tree/drivers/usb/core/message.c
===================================================================
--- local-tree.orig/drivers/usb/core/message.c  2004-09-23 23:52:51.736541393 +0200
+++ local-tree/drivers/usb/core/message.c       2004-09-24 02:06:57.401859258 +0200
@@ -17,6 +17,8 @@
 #include <linux/init.h>
 #include <linux/mm.h>
 #include <linux/timer.h>
+#include <linux/ctype.h>
+#include <linux/device.h>
 #include <asm/byteorder.h>
 
 #include "hcd.h"       /* for usbcore internals */
@@ -623,6 +625,20 @@
        return result;
 }
 
+static void usb_try_string_workarounds(unsigned char *buf, int *length)
+{
+       int newlength, oldlength = *length;
+
+       for(newlength = 2; newlength + 1 < oldlength; newlength += 2)
+               if (!isprint(buf[newlength]) || buf[newlength + 1])
+                       break;
+
+       if (newlength > 2) {
+               buf[0] = newlength;
+               *length = newlength;
+       }
+}
+
 static int usb_string_sub(struct usb_device *dev, unsigned int langid,
                unsigned int index, unsigned char *buf)
 {
@@ -634,19 +650,26 @@
 
        /* If that failed try to read the descriptor length, then
         * ask for just that many bytes */
-       if (rc < 0) {
+       if (rc < 2) {
                rc = usb_get_string(dev, langid, index, buf, 2);
                if (rc == 2)
                        rc = usb_get_string(dev, langid, index, buf, buf[0]);
        }
 
-       if (rc >= 0) {
+       if (rc >= 2) {
+               if (!buf[0] && !buf[1])
+                       usb_try_string_workarounds(buf, &rc);
+
                /* There might be extra junk at the end of the descriptor */
                if (buf[0] < rc)
                        rc = buf[0];
-               if (rc < 2)
-                       rc = -EINVAL;
+
+               rc = rc - (rc & 1); /* force a multiple of two */
        }
+
+       if (rc < 2)
+               rc = (rc < 0 ? rc : -EINVAL);
+
        return rc;
 }
 
@@ -677,7 +700,7 @@
 int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
 {
        unsigned char *tbuf;
-       int err;
+       int descriptor_type, err;
        unsigned int u, idx;
 
        if (size <= 0 || !buf || !index)
@@ -712,6 +735,8 @@
        if (err < 0)
                goto errout;
 
+       descriptor_type = tbuf[1];
+
        size--;         /* leave room for trailing NULL char in output buffer */
        for (idx = 0, u = 2; u < err; u += 2) {
                if (idx >= size)
@@ -724,6 +749,9 @@
        buf[idx] = 0;
        err = idx;
 
+       if (descriptor_type != USB_DT_STRING)
+               dev_dbg(&dev->dev, "string \"%s\" has wrong descriptor type %02x\n", 
buf, descriptor_type);
+
  errout:
        kfree(tbuf);
        return err;


-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to