]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/UsbMouse: Don't access key codes when length is wrong
authorRuiyu Ni <ruiyu.ni@intel.com>
Thu, 13 Sep 2018 08:09:10 +0000 (16:09 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Wed, 17 Oct 2018 03:04:03 +0000 (11:04 +0800)
Per USB HID spec, the buffer holding key codes should at least 3-byte
long.
Today's code assumes that the key codes buffer length is longer than
3-byte and unconditionally accesses the key codes buffer.
It's incorrect.
The patch fixes the issue by returning Device Error when the
length is less than 3-byte.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Steven Shi <steven.shi@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c

index 9324994975bc01b55301442ed069cb83c5f69b66..f4448bffe657221bfa7a1d29f94e9f9c88ea5c94 100644 (file)
@@ -811,8 +811,6 @@ OnMouseInterruptComplete (
     return EFI_SUCCESS;\r
   }\r
 \r
-  UsbMouseDevice->StateChanged = TRUE;\r
-\r
   //\r
   // Check mouse Data\r
   // USB HID Specification specifies following data format:\r
@@ -825,6 +823,12 @@ OnMouseInterruptComplete (
   // 2       0 to 7  Y displacement\r
   // 3 to n  0 to 7  Device specific (optional)\r
   //\r
+  if (DataLength < 3) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  UsbMouseDevice->StateChanged = TRUE;\r
+\r
   UsbMouseDevice->State.LeftButton  = (BOOLEAN) ((*(UINT8 *) Data & BIT0) != 0);\r
   UsbMouseDevice->State.RightButton = (BOOLEAN) ((*(UINT8 *) Data & BIT1) != 0);\r
   UsbMouseDevice->State.RelativeMovementX += *((INT8 *) Data + 1);\r