diff --git a/PS4Parser.cpp b/PS4Parser.cpp index 106d04ed..ca6adce4 100644 --- a/PS4Parser.cpp +++ b/PS4Parser.cpp @@ -62,7 +62,7 @@ uint8_t PS4Parser::getAnalogHat(AnalogHatEnum a) { } void PS4Parser::Parse(uint8_t len, uint8_t *buf) { - if (len > 0 && buf) { + if (len > 1 && buf) { #ifdef PRINTREPORT Notify(PSTR("\r\n"), 0x80); for (uint8_t i = 0; i < len; i++) { @@ -72,10 +72,17 @@ void PS4Parser::Parse(uint8_t len, uint8_t *buf) { #endif if (buf[0] == 0x01) // Check report ID - memcpy(&ps4Data, buf + 1, min(len - 1, sizeof(ps4Data))); - else if (buf[0] == 0x11) // This report is send via Bluetooth, it has an offset of 2 compared to the USB data - memcpy(&ps4Data, buf + 3, min(len - 3, sizeof(ps4Data))); - else { + memcpy(&ps4Data, buf + 1, min((uint8_t)(len - 1), sizeof(ps4Data))); + else if (buf[0] == 0x11) { // This report is send via Bluetooth, it has an offset of 2 compared to the USB data + if (len < 4) { +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nReport is too short: "), 0x80); + D_PrintHex (len, 0x80); +#endif + return; + } + memcpy(&ps4Data, buf + 3, min((uint8_t)(len - 3), sizeof(ps4Data))); + } else { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nUnknown report id: "), 0x80); D_PrintHex (buf[0], 0x80); diff --git a/PSBuzz.cpp b/PSBuzz.cpp index aa883712..498164d5 100644 --- a/PSBuzz.cpp +++ b/PSBuzz.cpp @@ -21,7 +21,7 @@ //#define PRINTREPORT // Uncomment to print the report send by the PS Buzz Controllers void PSBuzz::ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { - if (HIDUniversal::VID == PSBUZZ_VID && HIDUniversal::PID == PSBUZZ_PID && len > 0 && buf) { + if (HIDUniversal::VID == PSBUZZ_VID && HIDUniversal::PID == PSBUZZ_PID && len > 2 && buf) { #ifdef PRINTREPORT Notify(PSTR("\r\n"), 0x80); for (uint8_t i = 0; i < len; i++) { @@ -29,7 +29,7 @@ void PSBuzz::ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { Notify(PSTR(" "), 0x80); } #endif - memcpy(&psbuzzButtons, buf + 2, min(len - 2, sizeof(psbuzzButtons))); + memcpy(&psbuzzButtons, buf + 2, min((uint8_t)(len - 2), sizeof(psbuzzButtons))); if (psbuzzButtons.val != oldButtonState.val) { // Check if anything has changed buttonClickState.val = psbuzzButtons.val & ~oldButtonState.val; // Update click state variable