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 8BEC578003C for ; Thu, 28 Sep 2023 07:46:51 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=xoCfQHX6EjQN+0nrHFc3nuIYLmVQy3O6DrM6AYRhqPw=; 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=1695887210; v=1; b=GKnq+9EIHmsKG7ZNc9WmRKDD2cAY9gtyVsQnp2gw7rcxBg8B7dNbTuDWuli3wpVbLNhA18ru swvoPhXI5hNqFFdoak4ciMf40GcOSci0xh2mtb8kVHUz0J342ZvAFxih7+vFhgbubGKSP5iYPlD so/7pRZH7T0wYk2o6IyNJrZc= X-Received: by 127.0.0.2 with SMTP id CmR0YY7687511xzXCMn8DOf1; Thu, 28 Sep 2023 00:46:50 -0700 X-Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) by mx.groups.io with SMTP id smtpd.web11.8857.1695887209655896630 for ; Thu, 28 Sep 2023 00:46:49 -0700 X-Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-3513c435465so21775325ab.0 for ; Thu, 28 Sep 2023 00:46:49 -0700 (PDT) X-Gm-Message-State: jwCWU8cgvfSevDdHBfHhkY7tx7686176AA= X-Google-Smtp-Source: AGHT+IGhvavgeeKorf2IuAY4MyQOf/BtA/DjOkHtJqmOewmXDLKhHSXhpv5mU2+nmO/Jc5tO/vxAMQ== X-Received: by 2002:a05:6e02:1c46:b0:351:33b0:176e with SMTP id d6-20020a056e021c4600b0035133b0176emr425657ilg.12.1695887208775; Thu, 28 Sep 2023 00:46:48 -0700 (PDT) X-Received: from user-Latitude-5420.dc1.ventanamicro.com ([2401:4900:1cbc:99f:6dc7:3128:6646:ac3f]) by smtp.gmail.com with ESMTPSA id y13-20020a02ce8d000000b0043a1f6dc8d4sm4342751jaq.4.2023.09.28.00.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 00:46:48 -0700 (PDT) From: "Ranbir Singh" To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Ray Ni , Veeresh Sangolli Subject: [edk2-devel] [PATCH v1 1/2] FatPkg/EnhancedFatDxe: Fix SIGN_EXTENSION Coverity issues Date: Thu, 28 Sep 2023 13:16:38 +0530 Message-Id: <20230928074639.561998-2-rsingh@ventanamicro.com> In-Reply-To: <20230928074639.561998-1-rsingh@ventanamicro.com> References: <20230928074639.561998-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=GKnq+9EI; dmarc=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: 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 (#109139): https://edk2.groups.io/g/devel/message/109139 Mute This Topic: https://groups.io/mt/101633788/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-