Skip to content

Commit d927909

Browse files
LawstorantJiri Kosina
authored andcommitted
HID: pidff: Fix possible null pointer dereference
As reported by Dan Carpenter, if the axes_enable field wasn't found, trying to find the axes themselves will result in a null pointer dereference. This could only occur with a broken PID descriptor, but it's worth protecting from. Exit early if the axes_enable wasn't found AND add a gate to the pidff_find_special_keys to exit early if the passed HID field is null. This will protect again null dereferencing in the future and properly return 0 found special keys. Fixes: 1d72e7b ("HID: pidff: Add support for AXES_ENABLE field") Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Tomasz Pakuła <tomasz.pakula.oficjalny@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
1 parent 13120ab commit d927909

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

drivers/hid/usbhid/hid-pidff.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,9 @@ static int pidff_find_special_keys(int *keys, struct hid_field *fld,
11941194
{
11951195
int found = 0;
11961196

1197+
if (!fld)
1198+
return 0;
1199+
11971200
for (int i = 0; i < count; i++) {
11981201
keys[i] = pidff_find_usage(fld, usage_page | usagetable[i]) + 1;
11991202
if (keys[i])
@@ -1299,19 +1302,21 @@ static int pidff_find_special_fields(struct pidff_device *pidff)
12991302
return -1;
13001303
}
13011304

1302-
if (!pidff->axes_enable)
1305+
if (!pidff->axes_enable) {
13031306
hid_info(pidff->hid, "axes enable field not found!\n");
1304-
else
1305-
hid_dbg(pidff->hid, "axes enable report count: %u\n",
1306-
pidff->axes_enable->report_count);
1307+
return 0;
1308+
}
1309+
1310+
hid_dbg(pidff->hid, "axes enable report count: %u\n",
1311+
pidff->axes_enable->report_count);
13071312

13081313
uint found = PIDFF_FIND_GENERAL_DESKTOP(direction_axis_id, axes_enable,
13091314
direction_axis);
13101315

13111316
pidff->axis_count = found;
13121317
hid_dbg(pidff->hid, "found direction axes: %u", found);
13131318

1314-
for (int i = 0; i < sizeof(pidff_direction_axis); i++) {
1319+
for (int i = 0; i < ARRAY_SIZE(pidff_direction_axis); i++) {
13151320
if (!pidff->direction_axis_id[i])
13161321
continue;
13171322

0 commit comments

Comments
 (0)