From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 1FB2D7803D9 for ; Tue, 20 Feb 2024 15:26:55 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=6SmpHW8NNFQt1vN1vZftgdBQ0rwkHCZxCZkL37PDfnY=; c=relaxed/simple; d=groups.io; h=DKIM-Filter:From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1708442814; v=1; b=w2iSRNLG8Gf7gYpcRVSHPgzn+7ZxeIiKwnKOTrR5i6SVNMVK178lmuBbeD4QWXOkY84ibxwp D6G4cRWwH/lHXOAykGyfqmafU5oBhJN1POY3t21zm8XDrq735+TjMgt48Kms6EEzNArWMDEPAzz cFxNRBypKODcXRpCZ286qD8w= X-Received: by 127.0.0.2 with SMTP id fLHnYY7687511xuG8N6WCqA8; Tue, 20 Feb 2024 07:26:54 -0800 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web10.15729.1708442814280243927 for ; Tue, 20 Feb 2024 07:26:54 -0800 X-Received: from localhost.localdomain (unknown [20.39.63.13]) by linux.microsoft.com (Postfix) with ESMTPSA id 658A22083614; Tue, 20 Feb 2024 07:26:53 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 658A22083614 From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Liming Gao , Gua Guo , Prakashan Krishnadas Veliyathuparambil , K N Karthik Subject: [edk2-devel] [PATCH v1 1/1] MdeModulePkg/TraceHubDebugSysTLib: Use wider type for loop comparisons Date: Tue, 20 Feb 2024 10:26:26 -0500 Message-Id: <20240220152626.238-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mikuback@linux.microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 6XIXSf0SCkEuJ8JCBcogdRxFx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=w2iSRNLG; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=linux.microsoft.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: Michael Kubacki 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 Cc: Gua Guo Cc: Prakashan Krishnadas Veliyathuparambil Cc: K N Karthik Signed-off-by: Michael Kubacki --- 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/BaseTraceHubDebugS= ysTLib.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSys= TLib.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; =20 if (NumberOfBytes =3D=3D 0) { // @@ -109,7 +109,7 @@ TraceHubSysTWriteCataLog64StatusCode ( MIPI_SYST_HEADER MipiSystHeader; RETURN_STATUS Status; UINT32 DbgInstCount; - UINT16 Index; + UINT32 Index; =20 if (Guid =3D=3D NULL) { return RETURN_INVALID_PARAMETER; diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebu= gSysTLib.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebu= gSysTLib.c index 35c239b5feae..6001f4dfd93d 100644 --- a/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLi= b.c +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLi= b.c @@ -45,7 +45,7 @@ TraceHubSysTDebugWrite ( MIPI_SYST_HANDLE MipiSystHandle; MIPI_SYST_HEADER MipiSystHeader; RETURN_STATUS Status; - UINT16 Index; + UINT32 Index; =20 if ((mDbgInstCount =3D=3D 0) || (mThDebugInstArray =3D=3D NULL)) { return RETURN_ABORTED; diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubAp= i.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; =20 DbgContext =3D GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); if (DbgContext !=3D NULL) { --=20 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] -=-=-=-=-=-=-=-=-=-=-=-