From nobody Fri Sep 06 18:35:36 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4X0lKP5ksKz5VSJ7; Fri, 06 Sep 2024 18:35:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X0lKP0z5Xz4WSN; Fri, 6 Sep 2024 18:35:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725647737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pKCpINCa1gbJbWjJeVDymlhmLpQJxxnYGHL2BTedaRM=; b=Rwl/5H63YQyFm3bQyn0/MHteV9rNiCWntddf7vmhxt+1y42HFsDRMv7bViWGhc8pmd0hEi VMIzQxmOvEf+wnpHEKZXcgC/TP1zr9WOpCNUrUvVL6NghdovVzGwAmKGC3leMpfQQNp+xC KZCxArZiMAOIIolaoxbntUsiebn4TpSKy8nsGL04g/7nf88E+3f5khxpT9HP95E/oeY6eA sZpKDP7WylIL0x5lJ1WZFBrwBIcU57A3c1QnYhRel3ntFFF7yjXoL5tOvbH2C/VHqrEks3 gB1k9s9STG68ivqGuvAeLdnfY6sCnwTGOTDSuShEP6Ul9lGI9PTxgN8qqcwjtw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725647737; a=rsa-sha256; cv=none; b=pluukDcGkevs/9v0RM5WXw8JjA1oLT/9IcrOeIbBoYLOnknDjHSpmEA2ZmUD8BFuzikgj6 xNtgX1/vq7r1Azpd8aPp4rLwCLK1rYT/n0iB3t4/+xd7kjVkv9dmP/D56Z6jE3zpUYgeAy u2cGNz7jT0R5ejC0OgUXoQPEJml8DMRWiBhB1pQlTG+4bSLeBREZEy2rwrJpUCj3mzUWoB ELF6Oli60HsmxlCv9bCIvnhMUUNjPoSxrQqpYndoGuQReL1RuArELgnBvn16V99ok9CTj/ 7P9orT7k0ISwoxPNQkkPxp+m48knRsyVDUuPgVY7ej//HGl7YRwSJZreWnmTcA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725647737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pKCpINCa1gbJbWjJeVDymlhmLpQJxxnYGHL2BTedaRM=; b=W4E+NqojrLheyC8EVybOgpqq8BNYbnzaSlXFsH9JHKXr2Bs/jU6PNpqG+k/qC9y/HOsZGv SWvVq4V6fSnU3GsxeF52EWNStln0rUZi2lhPqAPm1vkkb2X+4ZyTVDJlsZwOQT9jJaYkv/ IWYmCw5tmtvUVxq84gRfzziMGWqpx5kEyOPTnwF1TWVNrxuiL5Fv5kSRTEtLtUyUIdUqeR UK6fZRC25DzSCi/G4szMAE1g5CeA759sd2uDU86ioYVWjTnOS0SBkxMQahrhaZ+WmMNYCH 66P3C4c2iNyb0/uDcR5K7PW9F2Tv+LtUMix89mjQa/uiPPph1Cr1rOz/FAlj1A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4X0lKP0DNnz12nW; Fri, 6 Sep 2024 18:35:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 486IZaOU011855; Fri, 6 Sep 2024 18:35:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 486IZaO0011852; Fri, 6 Sep 2024 18:35:36 GMT (envelope-from git) Date: Fri, 6 Sep 2024 18:35:36 GMT Message-Id: <202409061835.486IZaO0011852@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 3f0efe05432b - main - libefivar: Fix AcpiEx print logic List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3f0efe05432b1633991114ca4ca330102a561959 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=3f0efe05432b1633991114ca4ca330102a561959 commit 3f0efe05432b1633991114ca4ca330102a561959 Author: Jose Luis Duran AuthorDate: 2024-08-20 11:58:00 +0000 Commit: Warner Losh CommitDate: 2024-09-06 18:34:33 +0000 libefivar: Fix AcpiEx print logic 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. Upstream PR: https://bugzilla.tianocore.org/show_bug.cgi?id=4555 Obtained from: https://github.com/tianocore/edk2/commit/96ed60dfd7d4818a532216d64ee87b13fae5c726 Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1388 --- lib/libefivar/efivar-dp-format.c | 72 +++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/lib/libefivar/efivar-dp-format.c b/lib/libefivar/efivar-dp-format.c index d97603c41dcb..72e024470a11 100644 --- a/lib/libefivar/efivar-dp-format.c +++ b/lib/libefivar/efivar-dp-format.c @@ -478,23 +478,41 @@ DevPathToTextAcpiEx ( ) { ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx; - CHAR8 *HIDStr; - CHAR8 *UIDStr; - CHAR8 *CIDStr; char HIDText[11]; char CIDText[11]; - - AcpiEx = DevPath; - HIDStr = (CHAR8 *)(((UINT8 *)AcpiEx) + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH)); - UIDStr = HIDStr + AsciiStrLen (HIDStr) + 1; - CIDStr = UIDStr + AsciiStrLen (UIDStr) + 1; + UINTN CurrentLength; + CHAR8 *CurrentPos; + UINTN NextStringOffset; + CHAR8 *Strings[3]; + UINT8 HidStrIndex; + UINT8 UidStrIndex; + UINT8 CidStrIndex; + UINT8 StrIndex; + + HidStrIndex = 0; + UidStrIndex = 1; + CidStrIndex = 2; + AcpiEx = DevPath; + Strings[HidStrIndex] = NULL; + Strings[UidStrIndex] = NULL; + Strings[CidStrIndex] = NULL; + CurrentLength = sizeof (ACPI_EXTENDED_HID_DEVICE_PATH); + CurrentPos = (CHAR8 *)(((UINT8 *)AcpiEx) + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH)); + StrIndex = 0; + while (CurrentLength < AcpiEx->Header.Length[0] && StrIndex < ARRAY_SIZE (Strings)) { + Strings[StrIndex] = CurrentPos; + NextStringOffset = AsciiStrLen (CurrentPos) + 1; + CurrentLength += NextStringOffset; + CurrentPos += NextStringOffset; + StrIndex++; + } if (DisplayOnly) { if ((EISA_ID_TO_NUM (AcpiEx->HID) == 0x0A03) || ((EISA_ID_TO_NUM (AcpiEx->CID) == 0x0A03) && (EISA_ID_TO_NUM (AcpiEx->HID) != 0x0A08))) { - if (AcpiEx->UID == 0) { - UefiDevicePathLibCatPrint (Str, "PciRoot(%s)", UIDStr); + if (Strings[UidStrIndex] != NULL) { + UefiDevicePathLibCatPrint (Str, "PciRoot(%s)", Strings[UidStrIndex]); } else { UefiDevicePathLibCatPrint (Str, "PciRoot(0x%x)", AcpiEx->UID); } @@ -503,8 +521,8 @@ DevPathToTextAcpiEx ( } if ((EISA_ID_TO_NUM (AcpiEx->HID) == 0x0A08) || (EISA_ID_TO_NUM (AcpiEx->CID) == 0x0A08)) { - if (AcpiEx->UID == 0) { - UefiDevicePathLibCatPrint (Str, "PcieRoot(%s)", UIDStr); + if (Strings[UidStrIndex] != NULL) { + UefiDevicePathLibCatPrint (Str, "PcieRoot(%s)", Strings[UidStrIndex]); } else { UefiDevicePathLibCatPrint (Str, "PcieRoot(0x%x)", AcpiEx->UID); } @@ -535,7 +553,10 @@ DevPathToTextAcpiEx ( (AcpiEx->CID >> 16) & 0xFFFF ); - if ((*HIDStr == '\0') && (*CIDStr == '\0') && (*UIDStr != '\0')) { + if (((Strings[HidStrIndex] != NULL) && (*Strings[HidStrIndex] == '\0')) && + ((Strings[CidStrIndex] != NULL) && (*Strings[CidStrIndex] == '\0')) && + ((Strings[UidStrIndex] != NULL) && (*Strings[UidStrIndex] != '\0'))) + { // // use AcpiExp() // @@ -544,7 +565,7 @@ DevPathToTextAcpiEx ( Str, "AcpiExp(%s,0,%s)", HIDText, - UIDStr + Strings[UidStrIndex] ); } else { UefiDevicePathLibCatPrint ( @@ -552,28 +573,25 @@ DevPathToTextAcpiEx ( "AcpiExp(%s,%s,%s)", HIDText, CIDText, - UIDStr + Strings[UidStrIndex] ); } } else { if (DisplayOnly) { - // - // display only - // - if (AcpiEx->HID == 0) { - UefiDevicePathLibCatPrint (Str, "AcpiEx(%s,", HIDStr); + if (Strings[HidStrIndex] != NULL) { + UefiDevicePathLibCatPrint (Str, "AcpiEx(%s,", Strings[HidStrIndex]); } else { UefiDevicePathLibCatPrint (Str, "AcpiEx(%s,", HIDText); } - if (AcpiEx->CID == 0) { - UefiDevicePathLibCatPrint (Str, "%s,", CIDStr); + if (Strings[CidStrIndex] != NULL) { + UefiDevicePathLibCatPrint (Str, "%s,", Strings[CidStrIndex]); } else { UefiDevicePathLibCatPrint (Str, "%s,", CIDText); } - if (AcpiEx->UID == 0) { - UefiDevicePathLibCatPrint (Str, "%s)", UIDStr); + if (Strings[UidStrIndex] != NULL) { + UefiDevicePathLibCatPrint (Str, "%s)", Strings[UidStrIndex]); } else { UefiDevicePathLibCatPrint (Str, "0x%x)", AcpiEx->UID); } @@ -584,9 +602,9 @@ DevPathToTextAcpiEx ( HIDText, CIDText, AcpiEx->UID, - HIDStr, - CIDStr, - UIDStr + Strings[HidStrIndex] != NULL ? Strings[HidStrIndex] : '\0', + Strings[CidStrIndex] != NULL ? Strings[CidStrIndex] : '\0', + Strings[UidStrIndex] != NULL ? Strings[UidStrIndex] : '\0' ); } }