public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael Kubacki" <mikuback@linux.microsoft.com>
To: devel@edk2.groups.io
Cc: Liming Gao <gaoliming@byosoft.com.cn>,
	Gua Guo <gua.guo@intel.com>,
	Prakashan Krishnadas Veliyathuparambil
	<krishnadas.veliyathuparambil.prakashan@intel.com>,
	K N Karthik <karthik.k.n@intel.com>
Subject: [edk2-devel] [PATCH v1 1/1] MdeModulePkg/TraceHubDebugSysTLib: Use wider type for loop comparisons
Date: Tue, 20 Feb 2024 10:26:26 -0500	[thread overview]
Message-ID: <20240220152626.238-1-mikuback@linux.microsoft.com> (raw)

From: Michael Kubacki <michael.kubacki@microsoft.com>

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>
---
 MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c   | 4 ++--
 MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.c | 2 +-
 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c        | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c
index 45dfd3127a4c..050210cb958b 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 35c239b5feae..6001f4dfd93d 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 fe946fe60c7d..035618faece5 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) {
-- 
2.40.1.vfs.0.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115655): https://edk2.groups.io/g/devel/message/115655
Mute This Topic: https://groups.io/mt/104469197/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



             reply	other threads:[~2024-02-20 15:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20 15:26 Michael Kubacki [this message]
2024-02-20 15:28 ` [edk2-devel] [PATCH v1 1/1] MdeModulePkg/TraceHubDebugSysTLib: Use wider type for loop comparisons Guo, Gua

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240220152626.238-1-mikuback@linux.microsoft.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox