HID: sony: Perform a boundry check on the sixaxis battery level index.
authorFrank Praznik <frank.praznik@oh.rr.com>
Thu, 20 Feb 2014 16:36:02 +0000 (11:36 -0500)
committerJiri Kosina <jkosina@suse.cz>
Mon, 24 Feb 2014 16:38:46 +0000 (17:38 +0100)
Make sure that an out-of-bounds read doesn't occur in the Sixaxis battery level
lookup table in the event that the controller sends an invalid battery status
value in the report.

Signed-off-by: Frank Praznik <frank.praznik@oh.rr.com>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-sony.c

index a51a9c0636be791dd76501aaa642602aa79f55f4..b39e3abd6cdd458b29e7d95eb6b5841f0db399a0 100644 (file)
@@ -854,7 +854,8 @@ static void sixaxis_parse_report(struct sony_sc *sc, __u8 *rd, int size)
                battery_capacity = 100;
                battery_charging = !(rd[30] & 0x01);
        } else {
-               battery_capacity = sixaxis_battery_capacity[rd[30]];
+               __u8 index = rd[30] <= 5 ? rd[30] : 5;
+               battery_capacity = sixaxis_battery_capacity[index];
                battery_charging = 0;
        }
        cable_state = !((rd[31] >> 4) & 0x01);