[SHELL32_APITEST] Follow-up to #6796 (25e2f5f)
[reactos.git] / drivers / usb / usbccgp / descriptor.c
index 37c496e..9499a0f 100644 (file)
@@ -11,6 +11,9 @@
 
 #include "usbccgp.h"
 
+#define NDEBUG
+#include <debug.h>
+
 NTSTATUS
 NTAPI
 USBCCGP_GetDescriptor(
@@ -288,7 +291,7 @@ DumpFullConfigurationDescriptor(
         DbgPrint("Descriptor Type %x Length %lu Offset %lu\n", Descriptor->bDescriptorType, Descriptor->bLength, ((ULONG_PTR)Descriptor - (ULONG_PTR)ConfigurationDescriptor));
 
         // check for invalid descriptors
-        if (!Descriptor->bLength) 
+        if (!Descriptor->bLength)
         {
             DbgPrint("Bogus Descriptor!!!\n");
             break;
@@ -323,6 +326,11 @@ USBCCGP_ScanConfigurationDescriptor(
     // count all interface descriptors
     //
     DescriptorCount = ConfigurationDescriptor->bNumInterfaces;
+    if (DescriptorCount == 0)
+    {
+        DPRINT1("[USBCCGP] DescriptorCount is zero\n");
+        return STATUS_INVALID_PARAMETER;
+    }
 
     //
     // allocate array holding the interface descriptors
@@ -336,6 +344,11 @@ USBCCGP_ScanConfigurationDescriptor(
         return STATUS_INSUFFICIENT_RESOURCES;
     }
 
+    //
+    // reset interface list count
+    //
+    FDODeviceExtension->InterfaceListCount = 0;
+
     do
     {
         //
@@ -347,6 +360,7 @@ USBCCGP_ScanConfigurationDescriptor(
             //
             // store in interface list
             //
+            ASSERT(FDODeviceExtension->InterfaceListCount < DescriptorCount);
             FDODeviceExtension->InterfaceList[FDODeviceExtension->InterfaceListCount].InterfaceDescriptor = InterfaceDescriptor;
             FDODeviceExtension->InterfaceListCount++;
         }
@@ -427,7 +441,7 @@ USBCCGP_SelectInterface(
     Status = USBCCGP_SyncUrbRequest(DeviceExtension->NextDeviceObject, Urb);
 
     //
-    // did it succeeed
+    // did it succeed
     //
     if (NT_SUCCESS(Status))
     {
@@ -542,4 +556,3 @@ USBCCGP_SelectConfiguration(
     //
     return Status;
 }
-