USB: gadget: Read buffer overflow
authorRoel Kluin <roel.kluin@gmail.com>
Thu, 6 Aug 2009 23:09:51 +0000 (16:09 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 23 Sep 2009 13:46:32 +0000 (06:46 -0700)
Check whether index is within bounds before testing the element.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/gadget/composite.c

index 59e8523..d05397e 100644 (file)
@@ -602,7 +602,7 @@ static int get_string(struct usb_composite_dev *cdev,
                        }
                }
 
-               for (len = 0; s->wData[len] && len <= 126; len++)
+               for (len = 0; len <= 126 && s->wData[len]; len++)
                        continue;
                if (!len)
                        return -EINVAL;