Skip to content

Commit

Permalink
MdeModulePkg/Bus/Pci/UhciDxe: Fix FORWARD_NULL Coverity issues
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
2 people authored and mergify[bot] committed Sep 22, 2023
1 parent e9f5d8c commit 28a267a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions MdeModulePkg/Bus/Pci/UhciDxe/UsbHcMem.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ UsbHcGetPciAddressForHostMem (
}

ASSERT ((Block != NULL));

if (Block == NULL) {
return 0;
}

//
// calculate the pci memory address for host memory address.
//
Expand Down Expand Up @@ -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
//
Expand Down

0 comments on commit 28a267a

Please sign in to comment.