From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web08.6082.1615887830929565525 for ; Tue, 16 Mar 2021 02:43:51 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: ianx.kuo@intel.com) IronPort-SDR: I68uXuuhx7DfP+0/DKo1ZVnTyq1w2AXTfgXgqLKlf+mn2qhffu4f8kIkP2f5PUTgcjdXRHB0AE 0tUHb3kEc7Hw== X-IronPort-AV: E=McAfee;i="6000,8403,9924"; a="189280270" X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="189280270" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 02:43:49 -0700 IronPort-SDR: 3fRDfk+9tQ5jCvhBgbzP1xEpNJoZQMD1wI5Q6nGyUZwbZkMfcNyc2O2W6OPleBR2H3yr3OtHQG xBaoOU/7pqUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="378813550" Received: from ikuox-tiger-lake-client-platform.itwn.intel.com ([10.5.215.23]) by fmsmga007.fm.intel.com with ESMTP; 16 Mar 2021 02:43:48 -0700 From: "IanX Kuo" To: devel@edk2.groups.io Cc: VincentX Ke Subject: [PATCH] ShellPkg/Library: Fix bug in Pci.c Date: Sat, 10 Apr 2021 01:34:45 +0800 Message-Id: <19d74844dec841c0c8dda5d6426c67d609ec9d44.1615887240.git.vincentx.ke@intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: VincentX Ke Bugzilla: 3262 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3262) No need to print PCIe details while CapabilityId is 0xFFFF. Limit the NextCapabilityOffset value to AllocatePool() memory. Signed-off-by: VincentX Ke --- ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c b/ShellPkg/L= ibrary/UefiShellDebug1CommandsLib/Pci.c index a2f04d8db5..9ebf1c26ef 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c @@ -2038,12 +2038,14 @@ LocatePciCapability ( =0D @param[in] PciExpressCap PCI Express capability buffer.=0D @param[in] ExtendedConfigSpace PCI Express extended configuration space.= =0D + @param[in] ExtendedConfigSize PCI Express extended configuration size.= =0D @param[in] ExtendedCapability PCI Express extended capability ID to exp= lain.=0D **/=0D VOID=0D PciExplainPciExpress (=0D IN PCI_CAPABILITY_PCIEXP *PciExpressCap,=0D IN UINT8 *ExtendedConfigSpace,=0D + IN UINTN ExtendedConfigSize,=0D IN CONST UINT16 ExtendedCapability=0D );=0D =0D @@ -2921,6 +2923,7 @@ ShellCommandRunPci ( PciExplainPciExpress (=0D (PCI_CAPABILITY_PCIEXP *) ((UINT8 *) &ConfigSpace + PcieCapabili= tyPtr),=0D ExtendedConfigSpace,=0D + ExtendedConfigSize,=0D ExtendedCapability=0D );=0D }=0D @@ -5698,12 +5701,14 @@ PrintPciExtendedCapabilityDetails( =0D @param[in] PciExpressCap PCI Express capability buffer.=0D @param[in] ExtendedConfigSpace PCI Express extended configuration space.= =0D + @param[in] ExtendedConfigSize PCI Express extended configuration size.= =0D @param[in] ExtendedCapability PCI Express extended capability ID to exp= lain.=0D **/=0D VOID=0D PciExplainPciExpress (=0D IN PCI_CAPABILITY_PCIEXP *PciExpressCap,=0D IN UINT8 *ExtendedConfigSpace,=0D + IN UINTN ExtendedConfigSize,=0D IN CONST UINT16 ExtendedCapability=0D )=0D {=0D @@ -5786,7 +5791,7 @@ PciExplainPciExpress ( }=0D =0D ExtHdr =3D (PCI_EXP_EXT_HDR*)ExtendedConfigSpace;=0D - while (ExtHdr->CapabilityId !=3D 0 && ExtHdr->CapabilityVersion !=3D 0) = {=0D + while (ExtHdr->CapabilityId !=3D 0 && ExtHdr->CapabilityVersion !=3D 0 &= & ExtHdr->CapabilityId !=3D 0xFFFF) {=0D //=0D // Process this item=0D //=0D @@ -5800,7 +5805,7 @@ PciExplainPciExpress ( //=0D // Advance to the next item if it exists=0D //=0D - if (ExtHdr->NextCapabilityOffset !=3D 0) {=0D + if (ExtHdr->NextCapabilityOffset !=3D 0 && (ExtHdr->NextCapabilityOffs= et <=3D (UINT32)(ExtendedConfigSize - sizeof (PCI_EXP_EXT_HDR)))) {=0D ExtHdr =3D (PCI_EXP_EXT_HDR*)(ExtendedConfigSpace + ExtHdr->NextCapa= bilityOffset - EFI_PCIE_CAPABILITY_BASE_OFFSET);=0D } else {=0D break;=0D --=20 2.18.0.windows.1