summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMichal Nazarewicz <mina86@mina86.com>2014-06-17 17:47:41 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-07-09 11:14:00 -0700
commit4882c04833f6fdb0d27c398150589f68b3d89b4a (patch)
tree21b728ccc167dab7718c6230c9c252bf5485895f /drivers
parent086d371dff6431caf9e41e9a761b98478542ef3a (diff)
downloadlinux-3.10-4882c04833f6fdb0d27c398150589f68b3d89b4a.tar.gz
linux-3.10-4882c04833f6fdb0d27c398150589f68b3d89b4a.tar.bz2
linux-3.10-4882c04833f6fdb0d27c398150589f68b3d89b4a.zip
usb: gadget: f_fs: fix NULL pointer dereference when there are no strings
commit f0688c8b81d2ea239c3fb0b848f623b579238d99 upstream. If the descriptors do not need any strings and user space sends empty set of strings, the ffs->stringtabs field remains NULL. Thus *ffs->stringtabs in functionfs_bind leads to a NULL pointer dereferenece. The bug was introduced by commit [fd7c9a007f: “use usb_string_ids_n()”]. While at it, remove double initialisation of lang local variable in that function. ffs->strings_count does not need to be checked in any way since in the above scenario it will remain zero and usb_string_ids_n() is a no-operation when colled with 0 argument. Signed-off-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/gadget/f_fs.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index b6e9d917221..84219f65605 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -1389,11 +1389,13 @@ static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev)
ffs->ep0req->context = ffs;
lang = ffs->stringtabs;
- for (lang = ffs->stringtabs; *lang; ++lang) {
- struct usb_string *str = (*lang)->strings;
- int id = first_id;
- for (; str->s; ++id, ++str)
- str->id = id;
+ if (lang) {
+ for (; *lang; ++lang) {
+ struct usb_string *str = (*lang)->strings;
+ int id = first_id;
+ for (; str->s; ++id, ++str)
+ str->id = id;
+ }
}
ffs->gadget = cdev->gadget;