Commits

Liam Staskawicz  committed 4d3af05

descriptor: bounds checking for interface and endpoint indexes

  • Participants
  • Parent commits 58df97e

Comments (0)

Files changed (3)

File src/descriptor.c

 
 #include "usbus.h"
 #include "usbus_private.h"
+#include "usbus_limits.h"
+#include "logger.h"
 
 #include <string.h>
 
         return UsbusNotOpen;
     }
 
+    if (index >= USBUS_MAX_INTERFACES) {
+        return UsbusBadParameter;
+    }
+
     return gPlatform->getInterfaceDescriptor(d, index, altsetting, desc);
 }
 
-int usbusGetEndpointDescriptor(UsbusDevice *d, unsigned intfIndex, unsigned ep, struct UsbusEndpointDescriptor *desc)
+int usbusGetEndpointDescriptor(UsbusDevice *d, unsigned intfIndex, unsigned epIndex, struct UsbusEndpointDescriptor *desc)
 {
     if (!d->isOpen) {
         return UsbusNotOpen;
     }
 
-    return gPlatform->getEndpointDescriptor(d, intfIndex, ep, desc);
+    if (intfIndex >= USBUS_MAX_INTERFACES) {
+        logdebug("usbusGetEndpointDescriptor(): intfIndex (%d) >= USBUS_MAX_INTERFACES", intfIndex);
+        return UsbusBadParameter;
+    }
+
+    if (epIndex >= USBUS_MAX_ENDPOINTS) {
+        logdebug("usbusGetEndpointDescriptor(): epIndex (%d) >= USBUS_MAX_ENDPOINTS", epIndex);
+        return UsbusBadParameter;
+    }
+
+    return gPlatform->getEndpointDescriptor(d, intfIndex, epIndex, desc);
 }
 
 int usbusGetStringDescriptor(UsbusDevice *d, uint8_t index, uint16_t lang, uint8_t *buf, unsigned len, unsigned *transferred)

File src/platform/iokit.c

 {
     IOUSBInterfaceInterface_t **intf = d->iokit.interfaces[intfIndex].intf;
 
+    if (!intf) {
+        logdebug("iokitGetEndpointDescriptor(): interface %d has not been opened", intfIndex);
+        return UsbusNotOpen;
+    }
+
     UInt8 direction;
     UInt8 number;
     UInt8 transferType;
     UsbusStalled,
     UsbusOverflow,
     UsbusTimeout,
+    UsbusBadParameter,
     UsbusStatusGenericError
 };
 
 
 int usbusGetConfigDescriptor(UsbusDevice *d, unsigned index, struct UsbusConfigDescriptor *desc);
 int usbusGetInterfaceDescriptor(UsbusDevice *d, unsigned index, unsigned altsetting, struct UsbusInterfaceDescriptor *desc);
-int usbusGetEndpointDescriptor(UsbusDevice *d, unsigned intfIndex, unsigned ep, struct UsbusEndpointDescriptor *desc);
+int usbusGetEndpointDescriptor(UsbusDevice *d, unsigned intfIndex, unsigned epIndex, struct UsbusEndpointDescriptor *desc);
 
 int usbusClaimInterface(UsbusDevice *d, unsigned index);
 int usbusReleaseInterface(UsbusDevice *d, unsigned index);