[edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Fix FORWARD_NULL Coverity issues

Ranbir Singh via groups.io posted 1 patch 1 year, 4 months ago
Failed in applying to current master (apply log)
MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c | 11 +++++++++++
1 file changed, 11 insertions(+)
[edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Fix FORWARD_NULL Coverity issues
Posted by Ranbir Singh via groups.io 1 year, 4 months ago
The functions UsbHcGetHostAddrForPciAddr, UsbHcGetPciAddrForHostAddr
and UsbHcFreeMem do have

ASSERT ((Block != NULL));

statements after for loop, but these are applicable only in DEBUG mode.
In RELEASE mode, if for whatever reasons there is no match inside for
loop and the loop exits because of Block != NULL; condition, then there
is no "Block" NULL pointer check afterwards and the code proceeds to do
dereferencing "Block" which will lead to CRASH.

Hence, for safety add NULL pointer checks always.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4221
Signed-off-by: Ranbir Singh <Ranbir.Singh3@Dell.com>
---
MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
index d0ad1582e4..869ae6ec8a 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
@@ -261,6 +261,10 @@ UsbHcGetPciAddrForHostAddr (
}

ASSERT ((Block != NULL));
+  if (Block == NULL) {
+    return 0;
+  }
+
//
// calculate the pci memory address for host memory address.
//
@@ -310,6 +314,10 @@ UsbHcGetHostAddrForPciAddr (
}

ASSERT ((Block != NULL));
+  if (Block == NULL) {
+    return 0;
+  }
+
//
// calculate the pci memory address for host memory address.
//
@@ -590,6 +598,9 @@ UsbHcFreeMem (
// the caller has passed in a wrong memory point
//
ASSERT (Block != NULL);
+  if (Block == NULL) {
+    return;
+  }

//
// Release the current memory block if it is empty and not the head
--
2.36.1.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97923): https://edk2.groups.io/g/devel/message/97923
Mute This Topic: https://groups.io/mt/96046873/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-