Skip to content

Commit

Permalink
[CHERRY-PICK] MdeModulePkg/TraceHubDebugSysTLib: Use wider type for l…
Browse files Browse the repository at this point in the history
…oop comparisons (microsoft#775)

## Description

Resolves a new CodeQL error due to the value being incremented in the
loop being a narrower type than the variable it is being compared
against.

The variable is changed to a UINT32 type so it has the same width as
the type it is being compared against.

Issue explanation: In a loop condition, comparison of a value of a
narrow type with a value of a wide type may result in unexpected
behavior if the wider value is sufficiently large (or small). This
is because the narrower value may overflow. This can lead to an
infinite loop.

Cc: Liming Gao <[email protected]>
Cc: Gua Guo <[email protected]>
Cc: Prakashan Krishnadas Veliyathuparambil
<[email protected]>
Cc: K N Karthik <[email protected]>
Signed-off-by: Michael Kubacki <[email protected]>
Reviewed-by: Gua Guo <[email protected]>
(cherry picked from commit 33c81c2)

- [ ] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [ ] 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

- CodeQL locally and in CI.
- MdeModulePkg build and CI.

## Integration Instructions

N/A
  • Loading branch information
makubacki authored Mar 20, 2024
1 parent 6cc02e2 commit d093b84
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TraceHubSysTDebugWrite (
MIPI_SYST_HEADER MipiSystHeader;
RETURN_STATUS Status;
UINT32 DbgInstCount;
UINT16 Index;
UINT32 Index;

if (NumberOfBytes == 0) {
//
Expand Down Expand Up @@ -109,7 +109,7 @@ TraceHubSysTWriteCataLog64StatusCode (
MIPI_SYST_HEADER MipiSystHeader;
RETURN_STATUS Status;
UINT32 DbgInstCount;
UINT16 Index;
UINT32 Index;

if (Guid == NULL) {
return RETURN_INVALID_PARAMETER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TraceHubSysTDebugWrite (
MIPI_SYST_HANDLE MipiSystHandle;
MIPI_SYST_HEADER MipiSystHeader;
RETURN_STATUS Status;
UINT16 Index;
UINT32 Index;

if ((mDbgInstCount == 0) || (mThDebugInstArray == NULL)) {
return RETURN_ABORTED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PackThDebugInstance (
)
{
UINT8 *DbgContext;
UINT16 Index;
UINT32 Index;

DbgContext = GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);
if (DbgContext != NULL) {
Expand Down

0 comments on commit d093b84

Please sign in to comment.