mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 08:42:13 +00:00
Bug 1403185 - Fix button value index lookup oob for Windows Gamepads; r=ted
We can get button indexes in HID usage reports that do not actually correspond to a button we store, meaning we can overstep bounds of the button array. Check validity before accessing array. MozReview-Commit-ID: AAQJLEgy2Ua
This commit is contained in:
parent
c3b3b2afe3
commit
c86096d041
@ -860,7 +860,14 @@ WindowsGamepadService::HandleRawInput(HRAWINPUT handle)
|
||||
memset(buttons.Elements(), 0, gamepad->numButtons * sizeof(bool));
|
||||
|
||||
for (unsigned i = 0; i < usageLength; i++) {
|
||||
buttons[usages[i] - 1] = true;
|
||||
// The button index in usages may be larger than what we detected when
|
||||
// enumerating gamepads. If so, warn and continue.
|
||||
//
|
||||
// Usage ID of 0 is reserved, so it should always be 1 or higher.
|
||||
if (NS_WARN_IF((usages[i] - 1u) >= buttons.Length())) {
|
||||
continue;
|
||||
}
|
||||
buttons[usages[i] - 1u] = true;
|
||||
}
|
||||
|
||||
if (gamepad->hasDpad) {
|
||||
|
Loading…
Reference in New Issue
Block a user