Skip to contentSkip to conversation

HID: core: do not allow parsing 0-sized reports

PATCH In review Dmitry Torokhov 2 participants 2 messages Apr 1 – Apr 9 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: core: do not allow parsing 0-sized reports

Commit d7db259bd6df ("HID: core: factor out hid_parse_collections()") reworked collection parsing code and inadvertently allowed returning "success" when parsing 0-sized reports where old code returned -EINVAL.

Restore the original behavior by doing an explicit check.

Note that the error message now differs from the generic "item fetching failed at offset %u/%u" that is now used only for non-empty descriptors.

Fixes d7db259bd6df ("HID: core: factor out hid_parse_collections()")
---
 drivers/hid/hid-core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/hid/hid-core.c +5 -0
index b40953e0f52e..be9d2b3356c3 100644
@@ -1272,6 +1272,11 @@ static int hid_parse_collections(struct hid_device *device)
 		device->collection[i].parent_idx = -1;
 
 	ret = -EINVAL;
+	if (start == end) {
+		hid_err(device, "rejecting 0-sized report descriptor\n");
+		goto out;
+	}
+
 	while ((next = fetch_item(start, end, &item)) != NULL) {
 		start = next;
 
Signature · 5 lines
2.53.0.1185.g05d4b7b318-goog


-- 
Dmitry
maintainer
#1 lore raw
Quoted 3 lines · Dmitry Torokhov

Commit d7db259bd6df ("HID: core: factor out hid_parse_collections()") reworked collection parsing code and inadvertently allowed returning "success" when parsing 0-sized reports where old code returned -EINVAL.

Ah, good catch, I've missed that.

Applied on top, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs