From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=WwAx0eom; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: gregx.yeh@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660199367; x=1691735367; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=bIdfzImet0PmAiMgeLk2R82fBC9bj1XJMOBYYCwoBMs=; b=WwAx0eom0JH53S3bjEDOLdq5kcIFNH2bdt1mUCfxxkYXikGmn5zTRe/o HjY4/oVKunVWEwjfafEZGVbyOP4UqEWmXrYtcP/9MvyxlFtecCzvAASmZ fSqwnlBWUL6RenWC97uHMyAWAj3NNOkFdx5RpoqLqNFO1an0mR/YgruBz yGZ+fsvHAFRm1XUq9KjI7PPGdjTe3UDX7YS9tna6j7LBFDPHFMzfPdh9x 1YBHwQWXKHUW7tI67fAUCRrNai0nokLfl3u/uACRzTxeEYwgHFXZ19ZN7 +diFDw1c6xgkyLUaSHgUPgAFD0y/S7bqomvftVywjccN5QdxbbiLCUv2J A==; 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" 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" 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: [PATCH] UefiPayloadPkg: Fix Coverity report defect Date: Thu, 11 Aug 2022 14:29:22 +0800 Message-Id: <20220811062922.2981-1-gregx.yeh@intel.com> X-Mailer: git-send-email 2.26.2.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 --- 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=0D )=0D {=0D - if ((Bridges =3D=3D NULL) && (Count =3D=3D 0)) {=0D + if ((Bridges =3D=3D NULL) || (Count =3D=3D 0)) {=0D return;=0D }=0D =0D - ASSERT (Bridges !=3D NULL && Count > 0);=0D + ASSERT (Bridges !=3D NULL || Count > 0);=0D =0D do {=0D --Count;=0D 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;=0D } else if (ElfCt->EiClass =3D=3D ELFCLASS64) {=0D Elf64Hdr =3D (Elf64_Ehdr *)ElfCt->FileBase;=0D - FileSize2 =3D (UINTN)(Elf64Hdr->e_shoff + Elf64Hdr->e_shentsize * Elf6= 4Hdr->e_shnum);=0D + FileSize2 =3D ((UINTN)Elf64Hdr->e_shoff + (UINTN)(Elf64Hdr->e_shentsiz= e * Elf64Hdr->e_shnum));=0D }=0D =0D *FileSize =3D MAX (FileSize1, FileSize2);=0D 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.=0D //=0D if (!Page1GSupport) {=0D - TotalPagesNum =3D ((NumberOfPdpEntriesNeeded + 1) * NumberOfPml4Entrie= sNeeded + 1) * NumberOfPml5EntriesNeeded + 1;=0D + TotalPagesNum =3D (UINTN)((NumberOfPdpEntriesNeeded + 1) * NumberOfPml= 4EntriesNeeded + 1) * NumberOfPml5EntriesNeeded + 1;=0D } else {=0D - TotalPagesNum =3D (NumberOfPml4EntriesNeeded + 1) * NumberOfPml5Entrie= sNeeded + 1;=0D + TotalPagesNum =3D (UINTN)(NumberOfPml4EntriesNeeded + 1) * NumberOfPml= 5EntriesNeeded + 1;=0D }=0D =0D //=0D --=20 2.26.2.windows.1