MdeModulePkg/Bus/Pci/UhciDxe: Fix FORWARD_NULL Coverity issues

The function UsbHcGetPciAddressForHostMem has

  ASSERT ((Block != NULL)); and

and the function UsbHcFreeMem has

  ASSERT (Block != NULL);

statement 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=4211

Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Co-authored-by: Veeresh Sangolli <veeresh.sangolli@dellteam.com>
Signed-off-by: Ranbir Singh <Ranbir.Singh3@Dell.com>
Signed-off-by: Ranbir Singh <rsingh@ventanamicro.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
This commit is contained in:
Ranbir Singh 2023-08-16 13:38:03 +08:00 committed by mergify[bot]
parent e9f5d8c0e0
commit 28a267af40

View File

@ -250,6 +250,11 @@ UsbHcGetPciAddressForHostMem (
}
ASSERT ((Block != NULL));
if (Block == NULL) {
return 0;
}
//
// calculate the pci memory address for host memory address.
//
@ -536,6 +541,10 @@ UsbHcFreeMem (
//
ASSERT (Block != NULL);
if (Block == NULL) {
return;
}
//
// Release the current memory block if it is empty and not the head
//