From nobody Fri May 17 10:13:19 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+109071+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+109071+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1695742144; cv=none; d=zohomail.com; s=zohoarc; b=gvq2cGSwdaH2/cH79bgagl15MeElCT7zlp2ZemVA3faLxWHH4kq5FEY1FG9rXYUmQr8xNnVibv++0mMtYXX30wbZ3lfVL7zJ9IL5CBD/WuHYqm4AV+cj81nj0UupmmGwJvTqZnMhJ/MjSsbGEeUq+4c7LieRJmPv7wmq+q0utGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695742144; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=HG3djMNiNGR5kE/BVpKY/qlcPzzG9gtoFnsHLvlXrXU=; b=ObzHrRaY+yIMNJQLBnopy9Mog/DggNbK6gDN0rVEHAtEryiJOA5XjXR5tWCWHndn383iPze6SmoHwB/e9ot7WZ2AEwn1Wp/FW1ewqzRLgWG2CMFTmWdif8kpfGw6+0DVLbu3tIMBsjJv/6wNv11gw0O4hj4vBqIfYfHgvgiD3E4= 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+109071+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 1695742144590310.70202757922243; Tue, 26 Sep 2023 08:29:04 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=wFi6xxFiE9qJlIV9BpY6eHPSjqETJ/4HFQUGMi5gFY0=; 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-Type:Content-Transfer-Encoding; s=20140610; t=1695742144; v=1; b=wuA4TsIlD7iuDGS350mFaneCAj6tHwEt2LQQvAVFeMz2YRWuiYHawkQFAtuy7XfKY+y0ZHbF PgxNk4pECdUpCzdKL+JFn+oa0DtdL8MIWjGz8zZ+tDi3cGkRkJK2kBfbuowp+tmBd0krFOkibtF hH6u/bbgsD5yFL5CMwM5oRIE= X-Received: by 127.0.0.2 with SMTP id QaQUYY1788612xSX5shXbyEr; Tue, 26 Sep 2023 08:29:04 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.22255.1695742143401404155 for ; Tue, 26 Sep 2023 08:29:03 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="361843612" X-IronPort-AV: E=Sophos;i="6.03,178,1694761200"; d="scan'208";a="361843612" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2023 08:29:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="819062659" X-IronPort-AV: E=Sophos;i="6.03,178,1694761200"; d="scan'208";a="819062659" X-Received: from malbecki-mobl2.igk.intel.com ([10.217.182.137]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2023 08:29:01 -0700 From: "Albecki, Mateusz" To: devel@edk2.groups.io Cc: Mateusz Albecki , Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH 1/1] MdePkg/UefiDevicePathLib: Fix AcpiEx print logic Date: Tue, 26 Sep 2023 17:28:30 +0200 Message-Id: <20230926152830.1394883-2-mateusz.albecki@intel.com> In-Reply-To: <20230926152830.1394883-1-mateusz.albecki@intel.com> References: <20230926152830.1394883-1-mateusz.albecki@intel.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,mateusz.albecki@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: ijXlLugp4O93xEnSu5XcXEbtx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1695742145062100001 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4555 Add logic that checks if the code doesn't overflow ACPI_EXTENDED_HID_DEVICE_PATH node when searching for optional strings. If the string is not provided in the device path node default value of "\0" is used. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Mateusz Albecki --- .../UefiDevicePathLib/DevicePathToText.c | 66 +++++++++++-------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c b/MdePkg/L= ibrary/UefiDevicePathLib/DevicePathToText.c index dd90dfa58e..5012dfef6b 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c @@ -418,23 +418,38 @@ DevPathToTextAcpiEx ( ) { ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx; - CHAR8 *HIDStr; - CHAR8 *UIDStr; - CHAR8 *CIDStr; CHAR16 HIDText[11]; CHAR16 CIDText[11]; - - AcpiEx =3D DevPath; - HIDStr =3D (CHAR8 *)(((UINT8 *)AcpiEx) + sizeof (ACPI_EXTENDED_HID_DEVIC= E_PATH)); - UIDStr =3D HIDStr + AsciiStrLen (HIDStr) + 1; - CIDStr =3D UIDStr + AsciiStrLen (UIDStr) + 1; + UINTN CurrentLength; + CHAR8 *CurrentPos; + UINTN NextStringOffset; + CHAR8 *Strings[3]; + CONST UINT8 HidStrIndex =3D 0; + CONST UINT8 UidStrIndex =3D 1; + CONST UINT8 CidStrIndex =3D 2; + UINT8 StrIndex; + + AcpiEx =3D DevPath; + Strings[HidStrIndex] =3D NULL; + Strings[UidStrIndex] =3D NULL; + Strings[CidStrIndex] =3D NULL; + CurrentLength =3D sizeof (ACPI_EXTENDED_HID_DEVICE_PATH); + CurrentPos =3D (CHAR8 *)(((UINT8 *)AcpiEx) + sizeof (ACPI_EXTE= NDED_HID_DEVICE_PATH)); + StrIndex =3D 0; + while (CurrentLength < AcpiEx->Header.Length[0] && StrIndex < ARRAY_SIZE= (Strings)) { + Strings[StrIndex] =3D CurrentPos; + NextStringOffset =3D AsciiStrLen (CurrentPos) + 1; + CurrentLength +=3D NextStringOffset; + CurrentPos +=3D NextStringOffset; + StrIndex++; + } =20 if (DisplayOnly) { if ((EISA_ID_TO_NUM (AcpiEx->HID) =3D=3D 0x0A03) || ((EISA_ID_TO_NUM (AcpiEx->CID) =3D=3D 0x0A03) && (EISA_ID_TO_NUM (= AcpiEx->HID) !=3D 0x0A08))) { - if (AcpiEx->UID =3D=3D 0) { - UefiDevicePathLibCatPrint (Str, L"PciRoot(%a)", UIDStr); + if (Strings[UidStrIndex] !=3D NULL) { + UefiDevicePathLibCatPrint (Str, L"PciRoot(%a)", Strings[UidStrInde= x]); } else { UefiDevicePathLibCatPrint (Str, L"PciRoot(0x%x)", AcpiEx->UID); } @@ -443,8 +458,8 @@ DevPathToTextAcpiEx ( } =20 if ((EISA_ID_TO_NUM (AcpiEx->HID) =3D=3D 0x0A08) || (EISA_ID_TO_NUM (A= cpiEx->CID) =3D=3D 0x0A08)) { - if (AcpiEx->UID =3D=3D 0) { - UefiDevicePathLibCatPrint (Str, L"PcieRoot(%a)", UIDStr); + if (Strings[UidStrIndex] !=3D NULL) { + UefiDevicePathLibCatPrint (Str, L"PcieRoot(%a)", Strings[UidStrInd= ex]); } else { UefiDevicePathLibCatPrint (Str, L"PcieRoot(0x%x)", AcpiEx->UID); } @@ -475,7 +490,7 @@ DevPathToTextAcpiEx ( (AcpiEx->CID >> 16) & 0xFFFF ); =20 - if ((*HIDStr =3D=3D '\0') && (*CIDStr =3D=3D '\0') && (*UIDStr !=3D '\0'= )) { + if ((Strings[HidStrIndex] =3D=3D NULL) && (Strings[CidStrIndex] =3D=3D N= ULL) && (Strings[UidStrIndex] !=3D NULL)) { // // use AcpiExp() // @@ -484,7 +499,7 @@ DevPathToTextAcpiEx ( Str, L"AcpiExp(%s,0,%a)", HIDText, - UIDStr + Strings[UidStrIndex] ); } else { UefiDevicePathLibCatPrint ( @@ -492,28 +507,25 @@ DevPathToTextAcpiEx ( L"AcpiExp(%s,%s,%a)", HIDText, CIDText, - UIDStr + Strings[UidStrIndex] ); } } else { if (DisplayOnly) { - // - // display only - // - if (AcpiEx->HID =3D=3D 0) { - UefiDevicePathLibCatPrint (Str, L"AcpiEx(%a,", HIDStr); + if (Strings[HidStrIndex] !=3D NULL) { + UefiDevicePathLibCatPrint (Str, L"AcpiEx(%a,", Strings[HidStrIndex= ]); } else { UefiDevicePathLibCatPrint (Str, L"AcpiEx(%s,", HIDText); } =20 - if (AcpiEx->CID =3D=3D 0) { - UefiDevicePathLibCatPrint (Str, L"%a,", CIDStr); + if (Strings[CidStrIndex] !=3D NULL) { + UefiDevicePathLibCatPrint (Str, L"%a,", Strings[CidStrIndex]); } else { UefiDevicePathLibCatPrint (Str, L"%s,", CIDText); } =20 - if (AcpiEx->UID =3D=3D 0) { - UefiDevicePathLibCatPrint (Str, L"%a)", UIDStr); + if (Strings[UidStrIndex] !=3D NULL) { + UefiDevicePathLibCatPrint (Str, L"%a)", Strings[UidStrIndex]); } else { UefiDevicePathLibCatPrint (Str, L"0x%x)", AcpiEx->UID); } @@ -524,9 +536,9 @@ DevPathToTextAcpiEx ( HIDText, CIDText, AcpiEx->UID, - HIDStr, - CIDStr, - UIDStr + Strings[HidStrIndex], + Strings[CidStrIndex], + Strings[UidStrIndex] ); } } --=20 2.39.2 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydz= ial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-31= 6 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu usta= wy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w trans= akcjach handlowych. Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata= i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wi= adomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiek= olwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the s= ole use of the intended recipient(s). If you are not the intended recipient= , please contact the sender and delete all copies; any review or distributi= on by others is strictly prohibited. -=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 (#109071): https://edk2.groups.io/g/devel/message/109071 Mute This Topic: https://groups.io/mt/101598228/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-