diff --git a/hidcomposite.cpp b/hidcomposite.cpp index 3f0a21c2..6cb866d3 100644 --- a/hidcomposite.cpp +++ b/hidcomposite.cpp @@ -306,6 +306,13 @@ void HIDComposite::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint // Fill in interface structure in case of new interface if(!piface) { + if(bNumIface >= maxHidInterfaces) { + // don't overflow hidInterfaces[] + Notify(PSTR("\r\n HIDComposite::EndpointXtract(): Not adding HID interface because we already have "), 0x80); + Notify(bNumIface, 0x80); + Notify(PSTR(" interfaces and can't hold more. "), 0x80); + return; + } piface = hidInterfaces + bNumIface; piface->bmInterface = iface; piface->bmAltSet = alt; @@ -320,6 +327,13 @@ void HIDComposite::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint index = 0; if(index) { + if(bNumEP >= totalEndpoints) { + // don't overflow epInfo[] either + Notify(PSTR("\r\n HIDComposite::EndpointXtract(): Not adding endpoint info because we already have "), 0x80); + Notify(bNumEP, 0x80); + Notify(PSTR(" endpoints and can't hold more. "), 0x80); + return; + } // Fill in the endpoint info structure epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F); epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize; diff --git a/hiduniversal.cpp b/hiduniversal.cpp index 49309df4..bbd06af7 100644 --- a/hiduniversal.cpp +++ b/hiduniversal.cpp @@ -308,6 +308,13 @@ void HIDUniversal::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint // Fill in interface structure in case of new interface if(!piface) { + if(bNumIface >= maxHidInterfaces) { + // don't overflow hidInterfaces[] + Notify(PSTR("\r\n HIDUniversal::EndpointXtract(): Not adding HID interface because we already have "), 0x80); + Notify(bNumIface, 0x80); + Notify(PSTR(" interfaces and can't hold more. "), 0x80); + return; + } piface = hidInterfaces + bNumIface; piface->bmInterface = iface; piface->bmAltSet = alt; @@ -319,6 +326,13 @@ void HIDUniversal::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint index = (pep->bEndpointAddress & 0x80) == 0x80 ? epInterruptInIndex : epInterruptOutIndex; if(index) { + if(bNumEP >= totalEndpoints) { + // don't overflow epInfo[] either + Notify(PSTR("\r\n HIDUniversal::EndpointXtract(): Not adding endpoint info because we already have "), 0x80); + Notify(bNumEP, 0x80); + Notify(PSTR(" endpoints and can't hold more. "), 0x80); + return; + } // Fill in the endpoint info structure epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F); epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize; diff --git a/usbhid.h b/usbhid.h index cf74f57d..e85ca575 100644 --- a/usbhid.h +++ b/usbhid.h @@ -149,7 +149,7 @@ protected: static const uint8_t epInterruptInIndex = 1; // InterruptIN endpoint index static const uint8_t epInterruptOutIndex = 2; // InterruptOUT endpoint index - static const uint8_t maxHidInterfaces = 3; + static const uint8_t maxHidInterfaces = 5; static const uint8_t maxEpPerInterface = 2; static const uint8_t totalEndpoints = (maxHidInterfaces * maxEpPerInterface + 1); // We need to make room for the control endpoint