USB HID: Usage Minimum and Usage Maximum are inclusive

Usage Minimum and Usage Maximum are an inclusive, closed interval.
This fixes an fencepost error where the Usage Maximum value was
not being included as a possible value in the bitfield. Related
to #17014


(cherry picked from commit 5ca608f519)
This commit is contained in:
John Thacker 2020-12-03 04:00:09 +00:00 committed by Gerald Combs
parent 935de5c4eb
commit 247f8a4b33
1 changed files with 9 additions and 3 deletions

View File

@ -6,6 +6,10 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
/* See specification at
* https://www.usb.org/sites/default/files/documents/hid1_11.pdf
* https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
*/
#include "config.h"
@ -3488,13 +3492,15 @@ parse_report_descriptor(report_descriptor_t *rdesc)
return FALSE;
usage_max = hid_unpack_value(data, i, size);
if (usage_min >= usage_max) {
if (usage_min > usage_max) {
goto err;
}
wmem_array_grow(field.usages, usage_max - usage_min);
for (guint32 j = usage_min; j < usage_max; j++)
/* min and max are inclusive */
wmem_array_grow(field.usages, usage_max - usage_min + 1);
for (guint32 j = usage_min; j <= usage_max; j++) {
wmem_array_append_one(field.usages, j);
}
defined ^= HID_USAGE_MIN;
break;