[edk2-devel] [PATCH] MdeModulePkg/Bus/Usb/UsbMouseDxe: Fix REVERSE_INULL Coverity issue

Ranbir Singh via groups.io Ranbir.Singh3=Dell.com at groups.io
Wed Jan 4 08:57:06 UTC 2023


The function USBMouseDriverBindingStart do have

ASSERT (UsbMouseDevice != NULL);

after AllocateZeroPool, but it is applicable only in DEBUG mode.
In RELEASE mode, the code proceeds to dereference "UsbMouseDevice"
which will lead to CRASH.

Hence, for safety add NULL pointer checks always. The ASSERT may be
retained or it may be deleted whatever is deemed more appropriate.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4222
Signed-off-by: Ranbir Singh <Ranbir.Singh3 at Dell.com>
---
MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c b/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c
index 451d4b934f..621d09713b 100644
--- a/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c
+++ b/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c
@@ -161,6 +161,10 @@ USBMouseDriverBindingStart (

UsbMouseDevice = AllocateZeroPool (sizeof (USB_MOUSE_DEV));
ASSERT (UsbMouseDevice != NULL);
+  if (UsbMouseDevice == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    goto ErrorExit;
+  }

UsbMouseDevice->UsbIo     = UsbIo;
UsbMouseDevice->Signature = USB_MOUSE_DEV_SIGNATURE;
--
2.36.1.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97924): https://edk2.groups.io/g/devel/message/97924
Mute This Topic: https://groups.io/mt/96046883/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/edk2-devel-archive/attachments/20230104/992d63b4/attachment.htm>


More information about the edk2-devel-archive mailing list