From nobody Mon May 6 17:48:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+92341+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+92341+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1660199369; cv=none; d=zohomail.com; s=zohoarc; b=HRHoy7eJxHQyTqsjBaWZ6Y/oa3vb6VUDmvuc1lqOuw0fzJgug+UE4VPNGFPk/LNprx4ncrW/D0QSkhbO41tnxkgdBAcwqhbon7ngikrPVDUUKEDTUtBkU3b7p4HROiUSLupBio48v/Q3F9VhFan/HxIXYkxBRPp7ig7Uouue+AA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660199369; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=O8WQLOvCyv1aSPjkKdRbdsSLG3Qg5JZQpA+Fo98UPqM=; b=YPlBGBlkpyioKcUxu6wo6UI8xN1Y/v0TXOpOX/JQI7AGu5/1fbbuljWgG54BzxN9cyIcxkz9CNl0KeC8wSN8qEi8YWWy48sHNxDFw6OSd+ElKCT+DLqtPtOBwB2oxkShKq3vN2c7aRKvPAroKNbvCZB8W8Di3Z0FOLzBmO1hiug= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+92341+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1660199369035780.2103838590217; Wed, 10 Aug 2022 23:29:29 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0es1YY1788612xeLY6DhZDJp; Wed, 10 Aug 2022 23:29:28 -0700 X-Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web08.3424.1660199367337319933 for ; Wed, 10 Aug 2022 23:29:27 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10435"; a="291271031" X-IronPort-AV: E=Sophos;i="5.93,228,1654585200"; d="scan'208";a="291271031" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Aug 2022 23:29:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,228,1654585200"; d="scan'208";a="673579217" X-Received: from chinghux-desk.gar.corp.intel.com ([10.5.215.36]) by fmsmga004.fm.intel.com with ESMTP; 10 Aug 2022 23:29:25 -0700 From: "GregX Yeh" To: devel@edk2.groups.io Cc: Gregx Yeh Subject: [edk2-devel] [PATCH] UefiPayloadPkg: Fix Coverity report defect Date: Thu, 11 Aug 2022 14:29:22 +0800 Message-Id: <20220811062922.2981-1-gregx.yeh@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,gregx.yeh@intel.com X-Gm-Message-State: iiUb46ausTrAQUoDXSAvpCD3x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1660199368; bh=zzVbNlpa1cAB+9QorSOU0sHqDTy13KE4PTo12HEzU7U=; h=Cc:Date:From:Reply-To:Subject:To; b=KEKa9hrIjA+Xu1pyhn+Q8spPm0TOlnaqiaLe16gSUcRJKi/zqXfYP+hrNXDQ2eNtO/Q P4VPTZGxwWwdJXijqWV4V5nbeS0Oji7G26Igh1Ixf6RAexDTw7UQA6REbtxtyjdbgwZ5H +QgBgNnVHdvhBMM70X/jsrPxiZxK2iyZvj8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1660199371468100003 Content-Type: text/plain; charset="utf-8" From: Gregx Yeh https://bugzilla.tianocore.org/show_bug.cgi?id=3D4018 Coverity report FORWARD_NULL and OVERFLOW_BEFORE_WIDEN potential defect in UefiPayloadPkg. Signed-off-by: Gregx Yeh Reviewed-by: James Lu --- UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 4 ++-- UefiPayloadPkg/PayloadLoaderPeim/ElfLib/ElfLib.c | 2 +- UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/U= efiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c index 9847063d3d..790e6109c0 100644 --- a/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c +++ b/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c @@ -232,11 +232,11 @@ PciHostBridgeFreeRootBridges ( UINTN Count ) { - if ((Bridges =3D=3D NULL) && (Count =3D=3D 0)) { + if ((Bridges =3D=3D NULL) || (Count =3D=3D 0)) { return; } =20 - ASSERT (Bridges !=3D NULL && Count > 0); + ASSERT (Bridges !=3D NULL || Count > 0); =20 do { --Count; diff --git a/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/ElfLib.c b/UefiPayload= Pkg/PayloadLoaderPeim/ElfLib/ElfLib.c index 2a6305c67b..a9bf6f3223 100644 --- a/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/ElfLib.c +++ b/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/ElfLib.c @@ -149,7 +149,7 @@ CalculateElfFileSize ( FileSize2 =3D Elf32Hdr->e_shoff + Elf32Hdr->e_shentsize * Elf32Hdr->e_= shnum; } else if (ElfCt->EiClass =3D=3D ELFCLASS64) { Elf64Hdr =3D (Elf64_Ehdr *)ElfCt->FileBase; - FileSize2 =3D (UINTN)(Elf64Hdr->e_shoff + Elf64Hdr->e_shentsize * Elf6= 4Hdr->e_shnum); + FileSize2 =3D ((UINTN)Elf64Hdr->e_shoff + (UINTN)(Elf64Hdr->e_shentsiz= e * Elf64Hdr->e_shnum)); } =20 *FileSize =3D MAX (FileSize1, FileSize2); diff --git a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c b/UefiPayl= oadPkg/UefiPayloadEntry/X64/VirtualMemory.c index 74b667a62a..8d8a9d0ca8 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c +++ b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c @@ -783,9 +783,9 @@ CreateIdentityMappingPageTables ( // Pre-allocate big pages to avoid later allocations. // if (!Page1GSupport) { - TotalPagesNum =3D ((NumberOfPdpEntriesNeeded + 1) * NumberOfPml4Entrie= sNeeded + 1) * NumberOfPml5EntriesNeeded + 1; + TotalPagesNum =3D (UINTN)((NumberOfPdpEntriesNeeded + 1) * NumberOfPml= 4EntriesNeeded + 1) * NumberOfPml5EntriesNeeded + 1; } else { - TotalPagesNum =3D (NumberOfPml4EntriesNeeded + 1) * NumberOfPml5Entrie= sNeeded + 1; + TotalPagesNum =3D (UINTN)(NumberOfPml4EntriesNeeded + 1) * NumberOfPml= 5EntriesNeeded + 1; } =20 // --=20 2.26.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#92341): https://edk2.groups.io/g/devel/message/92341 Mute This Topic: https://groups.io/mt/92953360/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-