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

The function UsbHcGetPciAddressForHostMem has

    ASSERT ((Block != NULL));

and the 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 the
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.

Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4210
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-07-03 19:44:24 +08:00 committed by mergify[bot]
parent f220dcbba8
commit dd49d448b0
1 changed files with 9 additions and 0 deletions

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
//