Improve HID parser error checking

pull/7/head
Robert Fisk 8 years ago
parent b8f10b6496
commit b30b82e27b

@ -182,16 +182,28 @@ HAL_StatusTypeDef Downstream_HID_Mouse_ParseReportDescriptor(void)
{ {
ReportXBitOffset = currentReportBitIndex + (currentReportSize * xUsageIndex); ReportXBitOffset = currentReportBitIndex + (currentReportSize * xUsageIndex);
ReportXBitLength = currentReportSize; ReportXBitLength = currentReportSize;
if ((ReportXBitOffset + ReportXBitLength) > (HID_MAX_REPORT_LEN * 8))
{
return HAL_ERROR;
}
} }
if (yUsageIndex != 0xFF) if (yUsageIndex != 0xFF)
{ {
ReportYBitOffset = currentReportBitIndex + (currentReportSize * yUsageIndex); ReportYBitOffset = currentReportBitIndex + (currentReportSize * yUsageIndex);
ReportYBitLength = currentReportSize; ReportYBitLength = currentReportSize;
if ((ReportYBitOffset + ReportYBitLength) > (HID_MAX_REPORT_LEN * 8))
{
return HAL_ERROR;
}
} }
if (wheelUsageIndex != 0xFF) if (wheelUsageIndex != 0xFF)
{ {
ReportWheelBitOffset = currentReportBitIndex + (currentReportSize * wheelUsageIndex); ReportWheelBitOffset = currentReportBitIndex + (currentReportSize * wheelUsageIndex);
ReportWheelBitLength = currentReportSize; ReportWheelBitLength = currentReportSize;
if ((ReportWheelBitOffset + ReportWheelBitLength) > (HID_MAX_REPORT_LEN * 8))
{
return HAL_ERROR;
}
} }
} }
break; break;
@ -201,10 +213,6 @@ HAL_StatusTypeDef Downstream_HID_Mouse_ParseReportDescriptor(void)
yUsageIndex = 0xFF; yUsageIndex = 0xFF;
wheelUsageIndex = 0xFF; wheelUsageIndex = 0xFF;
currentReportBitIndex += (currentReportSize * currentReportCount); currentReportBitIndex += (currentReportSize * currentReportCount);
if (currentReportBitIndex >= (HID_MAX_REPORT_LEN * 8))
{
return HAL_ERROR;
}
break; break;
} }
} }

Loading…
Cancel
Save