Skip to content

Conversation

@apop5
Copy link
Contributor

@apop5 apop5 commented Oct 24, 2025

Description

Codeql on MdeModulePkg/Libraries.

The majority of changes were unchecked return statuses that resulted in using variables which may be null/uninitialized.

There were some conditional uninitialized variables (depending on the conditionals, a variable would be uninitialized and then the value would be used)

One instance of switching to SafeIntLib to allow catching of overflow based on unvalidated input (from Hii).

this is a continuation of #11252 which went stale.

  • Breaking change?
  • Impacts security?
  • Includes tests?

How This Was Tested

Local CI using --codeql.
Verified by booting virtual platforms.

Integration Instructions

No integration necessary.

apop5 added 2 commits October 23, 2025 11:13
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>
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>
apop5 added 4 commits October 24, 2025 10:16
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>
https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Likely%20Bugs/Likely%20Typos/MissingEnumCaseInSwitch.qhelp

The case statement for PageId was missing a default case. This would
result in the code executing for all cases, which could result
in unintended hii codes being added with corrupt data.

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
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>
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>
@apop5 apop5 force-pushed the personal/apop5/mdemodulelibrariescodeql branch from 31278d5 to e61387b Compare October 24, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant