summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kubacki <michael.kubacki@microsoft.com>2024-02-15 14:20:07 -0500
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-02-26 23:13:08 +0000
commit33c81c25bbd55141ad395af89160b4ed4b703cdf (patch)
treeee12c8ab37694d63afe12232c2487645e0208a24
parentd25421d0d8cd2493b30215ef80d2424ecb19c870 (diff)
downloadedk2-33c81c25bbd55141ad395af89160b4ed4b703cdf.tar.gz
edk2-33c81c25bbd55141ad395af89160b4ed4b703cdf.tar.bz2
edk2-33c81c25bbd55141ad395af89160b4ed4b703cdf.zip
MdeModulePkg/TraceHubDebugSysTLib: Use wider type for loop comparisons
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 <gaoliming@byosoft.com.cn> Cc: Gua Guo <gua.guo@intel.com> Cc: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com> Cc: K N Karthik <karthik.k.n@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Gua Guo <gua.guo@intel.com>
-rw-r--r--MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c4
-rw-r--r--MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.c2
-rw-r--r--MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c2
3 files changed, 4 insertions, 4 deletions
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c
index 45dfd3127a..050210cb95 100644
--- a/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c
@@ -41,7 +41,7 @@ TraceHubSysTDebugWrite (
MIPI_SYST_HEADER MipiSystHeader;
RETURN_STATUS Status;
UINT32 DbgInstCount;
- UINT16 Index;
+ UINT32 Index;
if (NumberOfBytes == 0) {
//
@@ -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;
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.c
index 35c239b5fe..6001f4dfd9 100644
--- a/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.c
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.c
@@ -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;
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c
index fe946fe60c..035618faec 100644
--- a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c
@@ -56,7 +56,7 @@ PackThDebugInstance (
)
{
UINT8 *DbgContext;
- UINT16 Index;
+ UINT32 Index;
DbgContext = GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);
if (DbgContext != NULL) {