Skip to content

Commit

Permalink
MdePkg: Additional CodeQL fixes (#266)
Browse files Browse the repository at this point in the history
## Description

Fixes for additional CodeQL queries.

- [x] Impacts functionality?
  - **Functionality** - Does the change ultimately impact how firmware functions?
  - Examples: Add a new library, publish a new PPI, update an algorithm, ...
- [x] Impacts security?
  - **Security** - Does the change have a direct security impact on an application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
  - **Breaking change** - Will anyone consuming this change experience a break
    in build or boot behavior?
  - Examples: Add a new library class, move a module to a different repo, call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
  - **Documentation** - Does the change contain explicit documentation additions
    outside direct code modifications (and comments)?
  - Examples: Update readme file, add feature readme file, link to documentation
    on an a separate Web page, ...

## How This Was Tested

Build MdePkg and boot changes on QemuQ35Pkg to EFI shell.

## Integration Instructions

N/A

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
  • Loading branch information
makubacki authored and kenlautner committed Dec 18, 2023
1 parent 2c6ee99 commit 6acf82c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
11 changes: 4 additions & 7 deletions MdePkg/Library/BasePeCoffLib/BasePeCoff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,11 +1576,8 @@ PeCoffLoaderLoadImage (
return RETURN_LOAD_ERROR;
}

if ((Base == NULL) || (End == NULL)) {
DEBUG ((DEBUG_WARN | DEBUG_LOAD, "%a PeCoffLoaderImageAddress resolved NULL for Base (0x%p) or End (0x%p)\n", __FUNCTION__, Base, End));
}

if (Section->SizeOfRawData > 0) {
// MU_CHANGE - CodeQL change
if ((Section->SizeOfRawData > 0) && (Base != NULL)) {
Status = ImageContext->ImageRead (
ImageContext->Handle,
Section->PointerToRawData - TeStrippedOffset,
Expand All @@ -1596,8 +1593,8 @@ PeCoffLoaderLoadImage (
//
// If raw size is less then virtual size, zero fill the remaining
//

if (Size < Section->Misc.VirtualSize) {
// MU_CHANGE - CodeQL change - Assume Base is non-NULL if Size is non-zero
if ((Size < Section->Misc.VirtualSize) && (Base != NULL)) {
ZeroMem (Base + Size, Section->Misc.VirtualSize - Size);
}

Expand Down
16 changes: 14 additions & 2 deletions MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ DxePciSegmentLibPciRootBridgeIoReadWorker (
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;

PciRootBridgeIo = PciSegmentLibSearchForRootBridge (Address);
ASSERT (PciRootBridgeIo != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (PciRootBridgeIo == NULL) {
ASSERT (PciRootBridgeIo != NULL);
return 0;
}

// MU_CHANGE [END] - CodeQL change

PciRootBridgeIo->Pci.Read (
PciRootBridgeIo,
Expand Down Expand Up @@ -223,7 +229,13 @@ DxePciSegmentLibPciRootBridgeIoWriteWorker (
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;

PciRootBridgeIo = PciSegmentLibSearchForRootBridge (Address);
ASSERT (PciRootBridgeIo != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (PciRootBridgeIo == NULL) {
ASSERT (PciRootBridgeIo != NULL);
return 0;
}

// MU_CHANGE [END] - CodeQL change

PciRootBridgeIo->Pci.Write (
PciRootBridgeIo,
Expand Down

0 comments on commit 6acf82c

Please sign in to comment.