Commit graph

36559 commits

Author SHA1 Message Date
Michael Kubacki
fb2ac429de MdeModulePkg/UefiBootManagerLib: Add constructor to INF file
Some checks failed
CodeQL / Analyze (push) Has been cancelled
CodeQL / Analyze-1 (push) Has been cancelled
CodeQL / Analyze-2 (push) Has been cancelled
CodeQL / Analyze-3 (push) Has been cancelled
CodeQL / Analyze-4 (push) Has been cancelled
CodeQL / Analyze-5 (push) Has been cancelled
CodeQL / Analyze-6 (push) Has been cancelled
CodeQL / Analyze-7 (push) Has been cancelled
CodeQL / Analyze-8 (push) Has been cancelled
CodeQL / Analyze-9 (push) Has been cancelled
CodeQL / Analyze-10 (push) Has been cancelled
CodeQL / Analyze-11 (push) Has been cancelled
CodeQL / Analyze-12 (push) Has been cancelled
CodeQL / Analyze-13 (push) Has been cancelled
CodeQL / Analyze-14 (push) Has been cancelled
CodeQL / Analyze-15 (push) Has been cancelled
CodeQL / Analyze-16 (push) Has been cancelled
CodeQL / Analyze-17 (push) Has been cancelled
CodeQL / Analyze-18 (push) Has been cancelled
UPL Build / Build UPL VS2026 (push) Has been cancelled
UPL Build / Build UPL VS2026-1 (push) Has been cancelled
UPL Build / Build UPL GCC (push) Has been cancelled
UPL Build / Build UPL GCC-1 (push) Has been cancelled
UefiBootManagerLibConstructor() is a constructor function in BmBoot.c
that is missing as the constructor in the INF file.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-08-26 22:17:56 +00:00
JinKang
cc9a0425a2 ShellPkg/Shell: Preserve multi-instance device paths
EfiShellGetMapFromDevicePath() stops at any end-type node and
converts an end-instance node into an end-entire node. This truncates a
multi-instance device path and modifies the protocol data in place.

Walk until the end-entire node instead. This leaves intermediate
instances and the original device path unchanged.

Signed-off-by: JinKang <2371488344@qq.com>
2026-08-26 13:32:07 +02:00
rdiaz
2c2f74a581 SecurityPkg: Break out the user prompt from Tcg2 PPI
Break out the PromptForUserConfirmation() function into a lib
so it can be abstracted at the platform level.

Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
Signed-off-by: Bret Barkelew <brbarkel@microsoft.com>
2026-08-26 10:54:45 +00:00
rdiaz
ffaaf0f14c SecurityPkg: Introduce Dynamic TCG Log Scaling
Implemented dynamic TCG log scaling in Tcg2Dxe. When the log would become
truncated it instead now dynamically scales doubling the size each time.
An ERROR log is reported that an increase to your base log size should
occur such that scaling is not necessary. This is a precaution against
platforms that log a lot and the addition of new hashing algorithms for
PQC. The log is allocated in BootServices memory. Tests were added via
TcgLogTest which includes a DXE driver and a UEFI shell UnitTest app. The
DXE driver handles pre-ReadyToBoot tests while the TestApp handles
post-ReadyToBoot tests as well as gathering the test results from the DXE
driver. Markdown documents were created to detail the changes.

Added the Truncation event marker to the end of the FinalEventLog when it
becomes truncated. Added a event signal for when scaling occurs on the
normal event log. Consumers can trigger callbacks on this event; the test
app uses this to know when scaling occurs.

Added an ACPI log region for the ACPI table LAML/LASA. This region does
not scale and can become truncated indicated by the Truncation event
marker.

Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
2026-08-26 03:58:17 +00:00
Michael D Kinney
ef437b30ad MdeModulePkg/Core/Dxe: Add interrupt-enable nesting guard
Add interrupt-enable recursion depth tracking using
mInterruptEnableNestDepth and a bounded assertion in
CoreSetInterruptState().

This provides early detection for unintended recursive
interrupt-enable loops.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-08-25 23:36:26 +00:00
Michael D Kinney
1d2e73c4af MdeModulePkg/Core/Dxe: Refactor CoreSetInterruptState enable path
Refactor the CoreSetInterruptState(TRUE) flow so EnableInterrupt() is
invoked through a single call site.

Behavior is unchanged: interrupts remain disabled in SMM and are enabled
outside SMM.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-08-25 23:36:26 +00:00
James Lu
04679c85b4 PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe: Avoid torn RTC time reads
GetTime()/GetWakeupTime() wait for the RTC Update-In-Progress (UIP) bit to
clear, then read the time/date registers (offsets 0-9) back to back.  A clear
UIP bit only guarantees a documented minimum before the next update cycle
begins, not that the whole read fits inside it.  Where a single RTC access is
slow the read overruns that window and picks up undefined data from registers
the update cycle has disconnected from the bus; the corrupted field fails the
range check and GetTime() returns EFI_DEVICE_ERROR, which intermittently fails
OS boot and resume.

Read the registers through RtcReadTimeDateOrFail(), which samples the Seconds
register before the read and requires both UIP still clear and Seconds
unchanged afterwards.  The update cycle is specified to increment the stored
time, so Seconds changes if and only if an update occurred, which detects a
collision anywhere inside the read.  RtcReadRegistersSafe() drives that with at
most one retry and copies out only on success.  The full reasoning, including
why one retry is enough, is documented at those two functions.

The four read paths (GetTime, Init, GetWakeupTime, SetWakeupTime disable-alarm)
use the helper; write paths already inhibit updates via the Register B SET bit
and are unchanged.  The helper enters its own update-free window, so the
up-front RtcWaitToUpdate() in PcRtcGetTime() and in the PcRtcInit() read path is
now redundant and is removed.

Signed-off-by: James Lu <james.lu@intel.com>
2026-08-25 20:10:25 +00:00
Michael Kubacki
6acc33e779 pip-requirements.txt: Remove pylibfdt
pylibfdt currently fails to install. The pre-built wheel files are not
published and it fails to build from source due to having a floating
dependency on the swig package (specified in pylibfdt's pyproject.toml
file).

swig 4.5.0 was released on August 22, 2026 and removed support for
Python 2 APIs still being referenced in pylibfdt. These APIs were
already routing to the Python 3 APIs, but it is still a build break.

Originally, pip-requirements.txt was updated to have a direct git
dependency on the libfdt code in the upstream DTC repostiory.
However, there were concerns about building from source in different
environments with a preference to, at least temporarily, remove the
dependency until a sustainable solution can be found.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-08-25 19:24:45 +00:00
Michael Kubacki
48f4a7ab0b .github/workflows/upl-build.yml: Remove redundant pip requirements
This currently passes `pefile pylibfdt` to BuildPlatform.yml. However,
those are included in the same pip installation step that installs
the from pip-requirements.txt. This removes them so the dependency
details can be maintained in one place which is pip-requirements.txt.

This also allows local pip installation to install the same versions
installed in CI.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-08-25 19:24:45 +00:00
ramkumar.s
7735ed4f8e OvmfPkg/PlatformInitLib: Set dynamic MMIO window size to 1/4
Large multi-GPU passthrough configurations can exhaust the current
MMIO window sizing rule (1/8 of guest physical address space),
especially with newer GPUs that have very large BAR requirements and
alignment overhead.

With 46-bit guest physical addressing, the 1/8 rule provides an 8TB
MMIO window. Newer GPUs with 512GB VRAM can exhaust an 8TB window
when passing through up to 8 devices.

Increase the MMIO window size to 1/4 of guest physical address space.
This provides a 16TB MMIO window on a 46-bit setup.

Tested with 8-GPU passthrough (512GB VRAM per GPU). With this
change, all GPUs are visible and functional in the VM; without it,
one GPU was unusable.

Signed-off-by: ramkumar.s <ramkumar.s@nutanix.com>
2026-08-23 16:00:31 +03:00
Ivan Shapovalov
d98a39d4ce OvmfPkg/VirtioInputDxe: handle Ctrl-Alt-Del
Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
2026-08-21 12:52:57 +00:00
Ivan Shapovalov
1bc9b85452 OvmfPkg/VirtioInputDxe: implement key notifications
Presently, VirtioInputDxe accepts key notifications (RegisterKeyNotifyEx)
but does not act upon them. Despite ConSplitter correctly registering
notifications via all input devices (including PS/2 etc. devices
that implement key notifications correctly), emulators such as QEMU
stop sending input to non-virtio keyboards as soon as the virtio device
is claimed. As a result, preboot hotkeys are non-functional when virtio
is used.

Fixes: https://github.com/tianocore/edk2/issues/12887

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
2026-08-21 12:52:57 +00:00
Ivan Shapovalov
c1ece6ba0a OvmfPkg/VirtioInputDxe: maintain keyboard toggle state
In addition to maintaining full key state, we also need to maintain
explicit toggle (NumLock/CapsLock/ScrollLock) state. This completes
->KeyState->KeyToggleState handling and SetStateEx() implementation.

When a *Lock key is pressed, update the keyboard toggle state before
doing anything else. This must happen first, as this state is copied
into ->KeyState (and ->KeyState needs to be filled before ->Key, as
Shift state must be cleared after shifting a printable character).

When filling ->Key, apply CapsLock in series with Shift key handling
(CapsLock only applies to alphabetic characters, but otherwise it XORs
with Shift).

Finally, complete SetStateEx() implementation as we can now apply all
KeyToggleState bits properly.

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
2026-08-21 12:52:57 +00:00
Ivan Shapovalov
93be2ced1c OvmfPkg/VirtioInputDxe: fold Ctrl correctly
Folding Ctrl into a printable character to produce a C0 control code is
not specified by SIMPLE_TEXT_INPUT(_EX). We apply it for narrow
compatibility with other keyboard drivers and TerminalDxe; as such,
only apply it ReadKeyStroke (which is the only interface that does not
convey modifier state explicitly).

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
2026-08-21 12:52:57 +00:00
Ivan Shapovalov
1c76821458 OvmfPkg/VirtioInputDxe: fold Shift correctly
After applying Shift to a printable character, we must clear
`EFI_*_SHIFT_PRESSED` from ->KeyState to follow SIMPLE_TEXT_INPUT(_EX).

This means that ->KeyState must be populated before key code is parsed.

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
2026-08-21 12:52:57 +00:00
Ivan Shapovalov
30d146175f OvmfPkg/VirtioInputDxe: ReadKeyStrokeEx must always expose KeyState
Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
2026-08-21 12:52:57 +00:00
Ivan Shapovalov
434239eeab OvmfPkg/VirtioInputDxe: omit partial keystrokes
WaitForKey and ReadKeyStroke of SIMPLE_TEXT_INPUT must omit partial
keystrokes, as they do not return modifier and shift state (thus a
partial keystroke would read as an empty struct). Skip over partial
keystrokes in the key queue, should there be any.

Note that WaitForKeyEx of SIMPLE_TEXT_INPUT_EX must also omit partials,
thus it continues to share the implementation with WaitForKey -- unlike
ReadKeyStrokeEx and ReadKeyStroke.

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
2026-08-21 12:52:57 +00:00
Ivan Shapovalov
1c05d44715 OvmfPkg/VirtioInputDxe: add a EFI key queue for pending input
With support for partial keystrokes, the one-element "last key" buffer
is now actively lossy, as a single compound key press (such as Shift-S)
will produce two EFI_KEY_DATAs which will likely be processed in the
same GetDeviceData() loop, but only one of them would be retained.

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
2026-08-21 12:52:57 +00:00
Ivan Shapovalov
eaa78fc2f0 OvmfPkg/VirtioInputDxe: maintain key modifier state
- on each event, compute and save full key state at the time of event
  rather than just the input key itself
- correctly handle unrepresentable events (events which result in a
  null EFI scancode / Unicode value) and do not enqueue them as keys
  unless EFI_KEY_STATE_EXPOSED
- on ReadKeyStrokeEx, return the saved full key state rather than
  recompute modifier state based on potentially-changed data
- on SetStateEx, update EFI_KEY_STATE_EXPOSED
  (toggle state is not implemented yet)

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
2026-08-21 12:52:57 +00:00
Ivan Shapovalov
89152c91af OvmfPkg/VirtioInputDxe: do not set ScanCode together with UnicodeChar
EFI_INPUT_KEY's ->ScanCode and ->UnicodeChar are mutually exclusive.
The value space of ->ScanCode only includes representations of keys that
are not representable in Unicode (F1-F10, Esc, arrows etc.) and vice
versa. Furthermore, the integer representations of those fields overlap.
As such, writing ->UnicodeChar values into ->ScanCode is invalid and
produces bogus EFI_INPUT_KEYs that would compare inequal to any
well-formed values that might be passed into e.g. RegisterKeyNotifyEx.

Do not set ->ScanCode when a Unicode value is produced for a printable
character.

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
2026-08-21 12:52:57 +00:00
Ivan Shapovalov
aba8628e17 OvmfPkg/VirtioInputDxe: invert condition for matching KEY_PRESSED events
Technically, beyond KEY_PRESSED and its inverse KEY_RELEASED, a third
type of event is possible for autorepeated keystrokes.  Invert the
condition on Event->Value to handle autorepeat events as (successive)
key presses rather than repeated releases (essentially ignoring them).

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
2026-08-21 12:52:57 +00:00
Ivan Shapovalov
49583d582b OvmfPkg/VirtioInputDxe: include missing headers in VirtioInput.h
Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
2026-08-21 12:52:57 +00:00
Johnny.Fan
2970e5699b EmbeddedPkg/AcpiLib: Fix memory corruption in AcpiAmlObjectUpdateInteger
The original implementation of AcpiAmlObjectUpdateInteger had a critical
  bug when updating integer objects that were encoded with AML_ZERO_OP(0x00)
  or AML_ONE_OP(0x01), which are 1-byte optimized encodings.

  When the caller tried to update such an object to a value other than 0
  or 1, the code would:
  1. Overwrite the opcode byte with the new value's LSB
  2. This changed the opcode itself, e.g. 0x0B becomes AML_WORD_PREFIX
  3. Subsequent AML bytes (name segments of following objects) get
     misinterpreted as integer data
  4. Result: silent AML structure is silently corrupted, causing the OS to
     fail parsing ACPI tables and eventually crash.

  The fix:
  1. Only allow 0 -> 0 or 1 updates using the original 1-byte encoding
  2. For any other value, explicitly fail with a diagnostic
  3. Provide clear debug instructions on how to fix the ASL source

Reviewed-by: jie.fu <jie.fu@cixtech.com>
Signed-off-by: Johnny.Fan <Johnny.Fan@cixtech.com>
2026-08-12 08:13:56 +00:00
Corvin Köhne
86ecae29c6 Maintainers.txt: use my correct GitHub handle
I've missed that this handle should be my GitHub handle. Correct it to point
contributors to the right GitHub account.

Fixes: d795fb571b ("Maintainer.txt: add myself as reviewer for bhyve's OvmfPkg")
Signed-off-by: Corvin Köhne <corvink@FreeBSD.org>
2026-08-11 02:44:04 +00:00
Aaron Pop
816b35fe52 MdeModulePkg/UefiHiiLib: Fix regression from 12828
12828 introduced an ASSERT in HiiGetBrowserData() that fires when
InternalHiiBrowserCallback() returns NULL. This is a valid return
value indicating the browser has no data for the requested variable,
and callers already handle this by checking the FALSE return value.

The ASSERT is incorrect because it triggers on a non-error path,
causing a crash when the browser callback legitimately returns no data.
Remove the unnecessary ASSERT while keeping the existing FALSE return
so callers continue to handle this case gracefully.

Cc: Qihang Gao <gaoqihang@loongson.cn>
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-11 01:22:08 +00:00
Joey Vagedes
c5aa7e7d94 BaseTools/Build: Output warning message for library class mismatch
Performs a check that will verify that the library instance implements
the library specified in the dsc by ensuring a LIBRARY_CLASS definition
exists in the INF [Defines] section and the value matches the library it
says it is implementing.

As an example, from a platform dsc file:
BaseBmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf

BaseBmpSupportLib is supposed to be of library class BmpSupportLib, but the
dsc defines it incorrectly, the warning message will be displayed during
build.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
Co-authored-by: Poncho Figueroa <poncho.figueroa.esqueda@intel.com>
2026-08-06 04:55:34 +00:00
Michael Kubacki
909d1db4cb .pytool/Plugin/UncrustifyCheck: Update fork location in Readme.md
Updates the fork repo to the TianoCore Uncrustify fork at:
https://github.com/tianocore/uncrustify

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-08-06 02:35:50 +00:00
Michael Kubacki
e0d2cb29fe .pytool/Plugin/UncrustifyCheck: Run Black formatter
Runs the Black formatter against UncrustifyCheck.py so is formatted
to PEP-8. No functional changes are made.

https://pypi.org/project/black/

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-08-06 02:35:50 +00:00
Michael Kubacki
4074b5db5d .pytool/Plugin/UncrustifyCheck: Better support multi-repo workspaces
The plugin previously assumed that the workspace was a git repository
and made that pacakges would largely reside in that same repository.

A few changes are made to better support multi-repo workspaces:

1. Added a new method to find the git repo that contains the package
   being checked: `_get_git_repo_path()`.
2. Removes exceptions on git not being present and ignore/submodule
   exceptions.
3. Checks for git ignored files (and similar) in the repo containing
   the package being checked in `_get_git_ignored_paths()`.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-08-06 02:35:50 +00:00
Aaron Pop
d1c5d47014 MdeModulePkg: Fix unchecked return status
https://github.com/github/codeql/blob/codeql-cli-2.7.3/csharp/ql/src/API%20Abuse/UncheckedReturnValue.qhelp

When a function has a return status, it should
be checked to verify the function completed successfully.

Failing to check the return status can result in null pointer
dereferences or use of uninitialized variables.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 11:34:09 +00:00
Aaron Pop
1cc0af9d6d MdeModulePkg: Fix missing NULL tests
https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp

For items which allocate memory, or get a pointer from another
structure, it is important to validate that the pointers
are not null before they are dereferenced.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 11:34:09 +00:00
Aaron Pop
af24f366a4 MdeModulePkg: Fix comparison with wider widths
https://codeql.github.com/codeql-query-help/cpp/cpp-comparison-with-wider-type

If the narrow type (smaller range) is compared against a wide type
(larger range), the narrow value may overflow before reaching the wide
value. This can cause unexpected behavior, such as:

Infinite loops (loop condition never becomes false).
Incorrect logic (comparison results are misleading).

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 11:34:09 +00:00
Aaron Pop
72d0846c4c MdeModulePkg: Fix conditionally uninitialized variables
https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Security/CWE/CWE-457/ConditionallyUninitializedVariable.qhelp

Some local variables, when going through a code path, can
end up uninitialized (using the value they had at the start
of the function). This is generally due to an error path
that can occur based on the library instances, or the
unchecked error (i.e. a allocation failing).

These variables should be initialized with a known value
that will result in the function being able to exit
gracefully.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 08:59:15 +00:00
Aaron Pop
77cf8c8c10 MdeModulePkg: Fix missing NULL tests
https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp

For items which allocate memory, or get a pointer from another
structure, it is important to validate that the pointers
are not null before they are dereferenced.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 08:59:15 +00:00
Aaron Pop
476b78bbad MdeModulePkg: Fix Comparison overflow
https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Security/CWE/CWE-190/ComparisonWithWiderType.qhelp

Switch to using SafeUint16Add for calculating offsets into
block data. The data being used in the calculation comes from
config block strings, and there is no validation of the values
before the calculation occurs.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 06:27:20 +00:00
Aaron Pop
1d63461c91 MdeModulePkg: Fix missing NULL tests
https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp

For items which allocate memory, or get a pointer from another
structure, it is important to validate that the pointers
are not null before they are dereferenced.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 06:27:20 +00:00
Aaron Pop
8c66d98963 MdeModulePkg: Fix comparison with wider widths
https://codeql.github.com/codeql-query-help/cpp/cpp-comparison-with-wider-type

If the narrow type (smaller range) is compared against a wide type
(larger range), the narrow value may overflow before reaching the wide
value. This can cause unexpected behavior, such as:

Infinite loops (loop condition never becomes false).
Incorrect logic (comparison results are misleading).

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 06:27:20 +00:00
Aaron Pop
9b3ceeb254 MdeModulePkg: Fix missing NULL tests
https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp

For items which allocate memory, or get a pointer from another
structure, it is important to validate that the pointers
are not null before they are dereferenced.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 05:09:41 +00:00
Aaron Pop
dfd0edeb4e MdeModulePkg: Fix missing NULL tests
https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp

For items which allocate memory, or get a pointer from another
structure, it is important to validate that the pointers
are not null before they are dereferenced.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 03:07:16 +00:00
Aaron Pop
699382e342 MdeModulePkg: Fix unchecked return status
https://github.com/github/codeql/blob/codeql-cli-2.7.3/csharp/ql/src/API%20Abuse/UncheckedReturnValue.qhelp

When a function has a return status, it should
be checked to verify the function completed successfully.

Failing to check the return status can result in null pointer
dereferences or use of uninitialized variables.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 03:07:16 +00:00
Aaron Pop
0f0515f71b MdeModulePkg: Fix unchecked return status
https://github.com/github/codeql/blob/codeql-cli-2.7.3/csharp/ql/src/API%20Abuse/UncheckedReturnValue.qhelp

When a function has a return status, it should
be checked to verify the function completed successfully.

Failing to check the return status can result in null pointer
dereferences or use of uninitialized variables.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 02:13:24 +00:00
Aaron Pop
0bc1db4adf MdeModulePkg: Fix missing NULL tests
https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp

For items which allocate memory, or get a pointer from another
structure, it is important to validate that the pointers
are not null before they are dereferenced.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 02:13:24 +00:00
Aaron Pop
bf0dc7d787 MdeModulePkg: Fix comparison with wider widths
https://codeql.github.com/codeql-query-help/cpp/cpp-comparison-with-wider-type

If the narrow type (smaller range) is compared against a wide type
(larger range), the narrow value may overflow before reaching the wide
value. This can cause unexpected behavior, such as:

Infinite loops (loop condition never becomes false).
Incorrect logic (comparison results are misleading).

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2026-08-05 02:13:24 +00:00
Pierre Gondois
fa41c179db ShellPkg/EfiDecompress: Fix Codeql issues
Fix codeql reported issues by flattening MainCmdEfiDecompress(),
making it easier for the tool to evaluate potential risks.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-08-04 10:35:35 +03:00
Pierre Gondois
383e680c3c ShellPkg/Comp: Extract helper functions
Refactor the Comp command and extract 2 functions:
- OpenFileOperand()
- CompareFiles()

This allows to simplify the logic of MainCmdComp() and
fix some codeql reported potential errors.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-08-04 10:35:35 +03:00
Pierre Gondois
35a2f27546 ShellPkg/EfiDecompress: Check presence of decompression protocol
Check the return value of LocateProtocol() before
using the decompression protocol. This avoids a
potential NULL pointer derefence spotted by codeql.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-08-04 10:35:35 +03:00
Pierre Gondois
d9185d45c2 ShellPkg/Dmem: Refactor MainCmdDmem()
Refactor MainCmdDmem() to make it easier to understand.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-08-04 10:35:35 +03:00
Pierre Gondois
f260ae0375 ShellPkg/EfiCompress: Extract OpenFileHelper() and CompressFile()
Extract file opening and compression code into helpers.

Upon calling:
- gEfiShellProtocol->GetFileSize()
- gEfiShellProtocol->ReadFile()
the returned Status is now checked.

Upon calling AllocateZeroPool, the failed status is now set to
EFI_OUT_OF_RESOURCES.

Other than that, no functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-08-04 10:35:35 +03:00
Pierre Gondois
c089090278 ShellPkg/Pci: Extract ParsePciBdf()
Extract BDF argument parsing into a helper.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-08-04 10:35:35 +03:00
Pierre Gondois
ba2f216986 ShellPkg/Pci: Extract PciEnumerateAll()
Extract the default PCI enumeration path into a helper.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-08-04 10:35:35 +03:00