]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
error handling enhancement for possible null pointer dereference
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbKbDxe / KeyBoard.c
index 000430ae78d3353e635d27b6cd350cbb1e39af39..fe6121985c4e3a5a9bc9a6c979244228518bb617 100644 (file)
@@ -627,13 +627,18 @@ SetKeyboardLayoutEvent (
     //\r
     KeyCode = EfiKeyToUsbKeyCodeConvertionTable [(UINT8) (TempKey.Key)];\r
     TableEntry = GetKeyDescriptor (UsbKeyboardDevice, KeyCode);\r
+    if (TableEntry == NULL) {\r
+      ReleaseKeyboardLayoutResources (UsbKeyboardDevice);\r
+      FreePool (KeyboardLayout);\r
+      return;\r
+    }\r
     CopyMem (TableEntry, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR));\r
 \r
     //\r
     // For non-spacing key, create the list with a non-spacing key followed by physical keys.\r
     //\r
     if (TempKey.Modifier == EFI_NS_KEY_MODIFIER) {\r
-      UsbNsKey = AllocatePool (sizeof (USB_NS_KEY));\r
+      UsbNsKey = AllocateZeroPool (sizeof (USB_NS_KEY));\r
       ASSERT (UsbNsKey != NULL);\r
 \r
       //\r