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 6B7967803E4 for ; Wed, 27 Sep 2023 15:51:48 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=LzYKXBSilEiiPoVFIIVZn3fsvxcnSOCAGwXtpoDUhd4=; 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=1695829907; v=1; b=rpUog+7JetjhKKs0a9HIYg/4yrf8DsNaIaxcwHuBAUYRGlY4xKI09lXVtw9FiAaJKSXCG/kP UxU4AYq3en2sRPBkCxxS6zOGTv+D5cw2sbK30OUsiC1snl7yNL9lW3ieepUa9tzXOGvQ7gl/NOL brPHEdh8Bqs9mDyomlqo6ZUc= X-Received: by 127.0.0.2 with SMTP id 83eRYY7687511xOQw1OeARzG; Wed, 27 Sep 2023 08:51:47 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web11.21111.1695829902320589544 for ; Wed, 27 Sep 2023 08:51:46 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="372206108" X-IronPort-AV: E=Sophos;i="6.03,181,1694761200"; d="scan'208";a="372206108" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2023 08:51:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="752641419" X-IronPort-AV: E=Sophos;i="6.03,181,1694761200"; d="scan'208";a="752641419" X-Received: from kjurczyk-mobl1.ger.corp.intel.com (HELO malbecki-mobl2.intel.com) ([10.213.9.18]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2023 08:51:44 -0700 From: "Albecki, Mateusz" To: devel@edk2.groups.io Cc: Mateusz Albecki , Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCHv2 1/2] MdePkg/UefiDevicePathLib: Fix AcpiEx print logic Date: Wed, 27 Sep 2023 17:51:22 +0200 Message-Id: <20230927155123.1465365-2-mateusz.albecki@intel.com> In-Reply-To: <20230927155123.1465365-1-mateusz.albecki@intel.com> References: <20230927155123.1465365-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: XF5at1P1QIYeHwYMJt3Ab46zx7686176AA= Content-Type: text/plain; charset="us-ascii" 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=rpUog+7J; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=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 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 | 69 +++++++++++-------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c b/MdePkg/L= ibrary/UefiDevicePathLib/DevicePathToText.c index dd90dfa58e..bd8d1de201 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,10 @@ DevPathToTextAcpiEx ( (AcpiEx->CID >> 16) & 0xFFFF ); =20 - if ((*HIDStr =3D=3D '\0') && (*CIDStr =3D=3D '\0') && (*UIDStr !=3D '\0'= )) { + if (((Strings[HidStrIndex] !=3D NULL) && (*Strings[HidStrIndex] =3D=3D '= \0')) && + ((Strings[CidStrIndex] !=3D NULL) && (*Strings[CidStrIndex] =3D=3D '= \0')) && + ((Strings[UidStrIndex] !=3D NULL) && (*Strings[UidStrIndex] !=3D '\0= '))) + { // // use AcpiExp() // @@ -484,7 +502,7 @@ DevPathToTextAcpiEx ( Str, L"AcpiExp(%s,0,%a)", HIDText, - UIDStr + Strings[UidStrIndex] ); } else { UefiDevicePathLibCatPrint ( @@ -492,28 +510,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 +539,9 @@ DevPathToTextAcpiEx ( HIDText, CIDText, AcpiEx->UID, - HIDStr, - CIDStr, - UIDStr + Strings[HidStrIndex] !=3D NULL ? Strings[HidStrIndex] : '\0', + Strings[CidStrIndex] !=3D NULL ? Strings[CidStrIndex] : '\0', + Strings[UidStrIndex] !=3D NULL ? Strings[UidStrIndex] : '\0' ); } } --=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 (#109125): https://edk2.groups.io/g/devel/message/109125 Mute This Topic: https://groups.io/mt/101619978/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-