gspca: konica: add missing endpoint sanity check
authorJohan Hovold <johan@kernel.org>
Mon, 13 Mar 2017 12:53:59 +0000 (09:53 -0300)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 26 Aug 2017 01:13:58 +0000 (02:13 +0100)
commit aa58fedb8c7b6cf2f05941d238495f9e2f29655c upstream.

Make sure to check the number of endpoints to avoid accessing memory
beyond the endpoint array should a device lack the expected endpoints.

Note that, as far as I can tell, the gspca framework has already made
sure there is at least one endpoint in the current alternate setting so
there should be no risk for a NULL-pointer dereference here.

Fixes: b517af722860 ("V4L/DVB: gspca_konica: New gspca subdriver for
konica chipset using cams")

Cc: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Hans Verkuil <hansverk@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
[bwh: Backported to 3.2: adjust filename]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/media/video/gspca/konica.c

index f3f7fe0..9e0f5e2 100644 (file)
@@ -290,6 +290,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
                return -EIO;
        }
 
+       if (alt->desc.bNumEndpoints < 2)
+               return -ENODEV;
+
        packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
 
        reg_w(gspca_dev, sd->brightness, BRIGHTNESS_REG);