From 3a1d529668287a7b5b82a06e749d5d5cc1fd2e8e Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 7 Mar 2024 12:41:56 +0100 Subject: [PATCH] btstack_hid_parser: return false on parsing error in btstack_hid_get_report_size_for_id --- src/btstack_hid_parser.c | 5 ++++- src/btstack_hid_parser.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/btstack_hid_parser.c b/src/btstack_hid_parser.c index a2c995314..7c5d4fc7e 100644 --- a/src/btstack_hid_parser.c +++ b/src/btstack_hid_parser.c @@ -443,7 +443,10 @@ int btstack_hid_get_report_size_for_id(int report_id, hid_report_type_t report_t while (hid_descriptor_len){ int valid_report_type = 0; hid_descriptor_item_t item; - btstack_hid_parse_descriptor_item(&item, hid_descriptor, hid_descriptor_len); + bool ok = btstack_hid_parse_descriptor_item(&item, hid_descriptor, hid_descriptor_len); + if (ok == false) { + return 0; + } switch (item.item_type){ case Global: switch ((GlobalItemTag)item.item_tag){ diff --git a/src/btstack_hid_parser.h b/src/btstack_hid_parser.h index 3a52d70fb..8d220e412 100644 --- a/src/btstack_hid_parser.h +++ b/src/btstack_hid_parser.h @@ -194,6 +194,7 @@ bool btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8 * @param report_type * @param hid_descriptor_len * @param hid_descriptor + * @return report size in bytes or 0 on parsing error */ int btstack_hid_get_report_size_for_id(int report_id, hid_report_type_t report_type, uint16_t hid_descriptor_len, const uint8_t * hid_descriptor);