Skip to content

Commit 0b4e929

Browse files
authored
Fixed a regression related to HID report descriptors. (#210)
1 parent 3770e71 commit 0b4e929

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

common/usbx_host_classes/src/ux_host_class_hid_report_descriptor_get.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ UINT status;
112112
/* Check for correct transfer and entire descriptor returned. */
113113
if ((status == UX_SUCCESS) && (transfer_request -> ux_transfer_request_actual_length == length))
114114
{
115-
115+
UINT analysis_failure;
116116
/* Parse the report descriptor and build the report items. */
117117
while (length)
118118
{
119-
119+
/* Get one item from the report and analyze it. */
120120
/* Make sure this descriptor has at least the minimum length. */
121-
if(length < 3)
121+
analysis_failure = _ux_host_class_hid_report_item_analyse(descriptor, &item);
122+
if (analysis_failure)
122123
{
123-
124124
/* Error trap. */
125125
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED);
126126

@@ -130,10 +130,7 @@ UINT status;
130130
/* Return error status. */
131131
status = (UX_DESCRIPTOR_CORRUPTED);
132132
}
133-
134-
/* Get one item from the report and analyze it. */
135-
_ux_host_class_hid_report_item_analyse(descriptor, &item);
136-
133+
137134
/* Point the descriptor right after the item identifier. */
138135
descriptor += item.ux_host_class_hid_item_report_format;
139136

common/usbx_host_classes/src/ux_host_class_hid_report_item_analyse.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ UINT _ux_host_class_hid_report_item_analyse(UCHAR *descriptor, UX_HOST_CLASS_HI
7373
{
7474

7575
UCHAR item_byte;
76-
76+
UINT result = UX_SUCCESS;
7777

7878
/* Get the first byte from the descriptor. */
7979
item_byte = *descriptor;
@@ -89,11 +89,19 @@ UCHAR item_byte;
8989
/* Set the type. */
9090
item -> ux_host_class_hid_item_report_type = (item_byte >> 2) & 3;
9191

92-
/* Get its length (byte 1). */
93-
item -> ux_host_class_hid_item_report_length = (USHORT) *(descriptor + 1);
92+
/* Make sure descriptor has minimal length.*/
93+
if (sizeof(descriptor) >= 3)
94+
{
95+
/* Get its length (byte 1). */
96+
item -> ux_host_class_hid_item_report_length = (USHORT) *(descriptor + 1);
9497

95-
/* Then the tag (byte 2). */
96-
item -> ux_host_class_hid_item_report_tag = *(descriptor + 2);
98+
/* Then the tag (byte 2). */
99+
item -> ux_host_class_hid_item_report_tag = *(descriptor + 2);
100+
}
101+
else
102+
{
103+
result = UX_DESCRIPTOR_CORRUPTED;
104+
}
97105
}
98106
else
99107
{
@@ -124,6 +132,6 @@ UCHAR item_byte;
124132
}
125133

126134
/* Return successful completion. */
127-
return(UX_SUCCESS);
135+
return(result);
128136
}
129137

0 commit comments

Comments
 (0)