From d3e306f5f9be4a22afdbef8fd9f2e32aa3335aff Mon Sep 17 00:00:00 2001 From: Jun Wako Date: Sat, 26 Jun 2021 20:44:23 +0900 Subject: [PATCH] Fix buffer size and check maxPacketSize #646 --- hidboot.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hidboot.h b/hidboot.h index 4076400a..4fe83ffa 100644 --- a/hidboot.h +++ b/hidboot.h @@ -582,14 +582,18 @@ uint8_t HIDBoot::Poll() { // To-do: optimize manually, using the for loop only if needed. for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) { - const uint16_t const_buff_len = 16; - uint8_t buf[const_buff_len]; + const uint16_t const_buff_len = 64; USBTRACE3("(hidboot.h) i=", i, 0x81); USBTRACE3("(hidboot.h) epInfo[epInterruptInIndex + i].epAddr=", epInfo[epInterruptInIndex + i].epAddr, 0x81); USBTRACE3("(hidboot.h) epInfo[epInterruptInIndex + i].maxPktSize=", epInfo[epInterruptInIndex + i].maxPktSize, 0x81); uint16_t read = (uint16_t)epInfo[epInterruptInIndex + i].maxPktSize; + if (read > const_buff_len) + read = const_buff_len; + + uint8_t buf[read]; + rcode = pUsb->inTransfer(bAddress, epInfo[epInterruptInIndex + i].epAddr, &read, buf); // SOME buggy dongles report extra keys (like sleep) using a 2 byte packet on the wrong endpoint. // Since keyboard and mice must report at least 3 bytes, we ignore the extra data.