Merge pull request #647 from tmk/upstream_fix_hidboot_buff

hidboot: Fix buffer size and check maxPacketSize #646
This commit is contained in:
Kristian Sloth Lauszus 2021-07-15 13:23:39 +03:00 committed by GitHub
commit 395fca4aac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -582,14 +582,18 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() {
// To-do: optimize manually, using the for loop only if needed. // To-do: optimize manually, using the for loop only if needed.
for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) { for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) {
const uint16_t const_buff_len = 16; const uint16_t const_buff_len = 64;
uint8_t buf[const_buff_len];
USBTRACE3("(hidboot.h) i=", i, 0x81); USBTRACE3("(hidboot.h) i=", i, 0x81);
USBTRACE3("(hidboot.h) epInfo[epInterruptInIndex + i].epAddr=", epInfo[epInterruptInIndex + i].epAddr, 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); USBTRACE3("(hidboot.h) epInfo[epInterruptInIndex + i].maxPktSize=", epInfo[epInterruptInIndex + i].maxPktSize, 0x81);
uint16_t read = (uint16_t)epInfo[epInterruptInIndex + i].maxPktSize; 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); 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. // 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. // Since keyboard and mice must report at least 3 bytes, we ignore the extra data.