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 13F36D800FD for ; Tue, 7 Nov 2023 06:28:53 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=do23aME32TafUdIVvAcbie5PPUocXqva4Yx6wnCW8JA=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: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=1699338532; v=1; b=HOPhCRESLbi0gsk9XGsNVDJDdrvXBmQcDEorg2fzGqBoStCuBvmMfRnavTerkuTvMLtZ5Pj0 fiGkwi+/M1BHIhcCxI0encMNmuFisJOaN1dsJ64Ks76t6r7ATIyeRZJKc6BzyzesDLhGqQ5Jwej VPLwbgcxoVAQeOdnEXerYf6c= X-Received: by 127.0.0.2 with SMTP id anJHYY7687511x1OTYxLiyzo; Mon, 06 Nov 2023 22:28:52 -0800 X-Received: from mail-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) by mx.groups.io with SMTP id smtpd.web11.4718.1699338532047465844 for ; Mon, 06 Nov 2023 22:28:52 -0800 X-Received: by mail-il1-f174.google.com with SMTP id e9e14a558f8ab-359472f74c5so20944665ab.0 for ; Mon, 06 Nov 2023 22:28:51 -0800 (PST) X-Gm-Message-State: wKOrblRGHdQZW6Em5yJWKyQgx7686176AA= X-Google-Smtp-Source: AGHT+IFoFYzHQ2ZL/yvoMVf28ntT2Rliue+aygYLGxKyHbsCBdyDWiTuVR67bbUQIK9ccKbprku5jA== X-Received: by 2002:a05:6e02:1c8a:b0:359:42f7:47ea with SMTP id w10-20020a056e021c8a00b0035942f747eamr2134195ill.12.1699338531198; Mon, 06 Nov 2023 22:28:51 -0800 (PST) X-Received: from user-Latitude-5420.dc1.ventanamicro.com ([2401:4900:1f24:775d:7335:84a5:7d11:9393]) by smtp.gmail.com with ESMTPSA id c7-20020a0290c7000000b00463ff17540fsm1766626jag.78.2023.11.06.22.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 22:28:51 -0800 (PST) From: "Ranbir Singh" To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Ray Ni , Veeresh Sangolli Subject: [edk2-devel] [PATCH v2 1/2] FatPkg/EnhancedFatDxe: Fix SIGN_EXTENSION Coverity issues Date: Tue, 7 Nov 2023 11:58:41 +0530 Message-Id: <20231107062842.116670-2-rsingh@ventanamicro.com> In-Reply-To: <20231107062842.116670-1-rsingh@ventanamicro.com> References: <20231107062842.116670-1-rsingh@ventanamicro.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,rsingh@ventanamicro.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: 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=HOPhCRES; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=none From: Ranbir Singh The functions FatGetDirEntInfo and FatOpenDirEnt contains the code statements Cluster =3D (Entry->FileClusterHigh << 16) | Entry->FileCl= uster; and OFile->FileCluster =3D ((DirEnt->Entry.FileClusterHigh) << 16) | (Dir= Ent->Entry.FileCluster); respectively. As per Coverity report, in both these statements, there is an "Operand1" with type "UINT16" (16 bits, unsigned) which is promoted in "(Operand1 << 16) | Operand2" to type "int" (32 bits, signed), then sign- extended to type "unsigned long long" (64 bits, unsigned). If the result of "(Operand1 << 16) | Operand2" is greater than 0x7FFFFFFF, the upper bits of the result will all be 1. So to avoid sign-extension, typecast the Operand1 and then the inter- -mediate result after << 16 operation with UINTN. Note - UINTN is the data type of the variable on the LHS of the assignment. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4249 Cc: Ray Ni Co-authored-by: Veeresh Sangolli Signed-off-by: Ranbir Singh Signed-off-by: Ranbir Singh --- FatPkg/EnhancedFatDxe/DirectoryManage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FatPkg/EnhancedFatDxe/DirectoryManage.c b/FatPkg/EnhancedFatDx= e/DirectoryManage.c index 723fc35f38db..a21b7973cd21 100644 --- a/FatPkg/EnhancedFatDxe/DirectoryManage.c +++ b/FatPkg/EnhancedFatDxe/DirectoryManage.c @@ -474,7 +474,7 @@ FatGetDirEntInfo ( Info =3D Buffer;=0D Info->Size =3D ResultSize;=0D if ((Entry->Attributes & FAT_ATTRIBUTE_DIRECTORY) !=3D 0) {=0D - Cluster =3D (Entry->FileClusterHigh << 16) | Entry->FileC= luster;=0D + Cluster =3D (UINTN)((UINTN)(Entry->FileClusterHigh) << 16= ) | Entry->FileCluster;=0D Info->PhysicalSize =3D FatPhysicalDirSize (Volume, Cluster);=0D Info->FileSize =3D Info->PhysicalSize;=0D } else {=0D @@ -1167,7 +1167,7 @@ FatOpenDirEnt ( //=0D Volume =3D Parent->Volume;=0D OFile->FullPathLen =3D Parent->FullPathLen + 1 + StrLen (DirEnt->Fil= eString);=0D - OFile->FileCluster =3D ((DirEnt->Entry.FileClusterHigh) << 16) | (Di= rEnt->Entry.FileCluster);=0D + OFile->FileCluster =3D (UINTN)((UINTN)(DirEnt->Entry.FileClusterHigh= ) << 16) | (DirEnt->Entry.FileCluster);=0D InsertTailList (&Parent->ChildHead, &OFile->ChildLink);=0D } else {=0D //=0D --=20 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110817): https://edk2.groups.io/g/devel/message/110817 Mute This Topic: https://groups.io/mt/102438364/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-