]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
MdeModulePkg/UsbBusDxe: Add UsbControlTransfer() error check
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / UsbBus.c
index 78220222f6ed68953afebd86b68f9b5663db9146..7c58fe8d36a26a67dea4d3f9712f17fd88b27b7b 100644 (file)
@@ -2,7 +2,7 @@
 \r
     Usb Bus Driver Binding and Bus IO Protocol.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -76,6 +76,7 @@ UsbIoControlTransfer (
   USB_ENDPOINT_DESC       *EpDesc;\r
   EFI_TPL                 OldTpl;\r
   EFI_STATUS              Status;\r
+  UINTN                   RequestedDataLength;\r
 \r
   if (UsbStatus == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -86,6 +87,7 @@ UsbIoControlTransfer (
   UsbIf  = USB_INTERFACE_FROM_USBIO (This);\r
   Dev    = UsbIf->Device;\r
 \r
+  RequestedDataLength = DataLength;\r
   Status = UsbHcControlTransfer (\r
              Dev->Bus,\r
              Dev->Address,\r
@@ -99,6 +101,18 @@ UsbIoControlTransfer (
              &Dev->Translator,\r
              UsbStatus\r
              );\r
+  //\r
+  // If the request completed sucessfully and the Direction of the request is\r
+  // EfiUsbDataIn or EfiUsbDataOut, then make sure the actual number of bytes\r
+  // transfered is the same as the number of bytes requested.  If a different\r
+  // number of bytes were transfered, then return EFI_DEVICE_ERROR.\r
+  //\r
+  if (!EFI_ERROR (Status)) {\r
+    if (Direction != EfiUsbNoData && DataLength != RequestedDataLength) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto ON_EXIT;\r
+    }\r
+  }\r
 \r
   if (EFI_ERROR (Status) || (*UsbStatus != EFI_USB_NOERROR)) {\r
     //\r