ConfigDesc = (EFI_USB_CONFIG_DESCRIPTOR *) PeiUsbDevice->ConfigurationData;\r
ConfigDescLength = ConfigDesc->TotalLength;\r
\r
+ //\r
+ // Reject if TotalLength even cannot cover itself.\r
+ //\r
+ if (ConfigDescLength < OFFSET_OF (EFI_USB_CONFIG_DESCRIPTOR, TotalLength) + sizeof (ConfigDesc->TotalLength)) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ //\r
+ // Reject if TotalLength exceeds the PeiUsbDevice->ConfigurationData.\r
+ //\r
+ if (ConfigDescLength > sizeof (PeiUsbDevice->ConfigurationData)) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
//\r
// Then we get the total descriptors for this configuration\r
//\r