From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (EUR02-VE1-obe.outbound.protection.outlook.com [40.92.69.41]) by mx.groups.io with SMTP id smtpd.web12.1504.1571573315251344544 for ; Sun, 20 Oct 2019 05:08:35 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@outlook.com header.s=selector1 header.b=BEF4KO7z; spf=pass (domain: outlook.com, ip: 40.92.69.41, mailfrom: marvin.haeuser@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lkvEYSzk7SU1o1jWtFsoMn2rwCbw7MrW9Vv0SIihp/9kMfesmJ/U7Wm5TDWYUJMdvHZ8AsXAU0eAT40RMr11/uugdah686tN8B0hI/jZPArflnkakAPh2StnpooPvd5dL/Me+mBaPouD+IJJMYNnXBvY+a7TIRVkfFSI2ZBeyRipO8vysbkyvIdFGxnY2bgCCLVLVcSvBudJaJbh1YZTHiOKVVQVKBKyi2qrS6pnDev7fkxYcHHst2X8KLeagS0fQ8zI8eoClJLX4J2JXDt/qmgW3Ra+6bbywZpoN8vKc/M7+EPpncJIRqWEph+IZzzyafPT2b0B88hVyjDvqUUqDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SCNvtkqACwvkdjk5ndvnnKJJ9XAf0TdgKReEHiZ0Oc0=; b=iO02bz+atd7g7StFQVIYqsj/fuKmdl2vMnpN8VBnZsFH6k/fZerk22xlgvOL7yNe+HqN4b4LmkLEAAzQ/UanSQrz7s2isQuEFr6A1kZQIbKtY+Srahczugan+3Nj2D8QmA8Akpk8Hebj2hhRJshGWJEr/aiQZTUe2O7sDveP9rqATPQLj9imT0bsGJUQvt8SCPJpAIKLaGByLY4r0Zyj9WzsJF+aONXncx14xivJb2trqOvWp+GXNKiQEO7lpuQ8i0+nUArulz7HXhsVlA+OdyxD4H6L2qCY5xf1qVWIClotauNPn6SYJ72HPjdssgwhHmqWPZ4mZcwT4Y43Zb/9rQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SCNvtkqACwvkdjk5ndvnnKJJ9XAf0TdgKReEHiZ0Oc0=; b=BEF4KO7zy/Pd0aFWHsGmkhN9BaMenKu/oy0Cs7mpciwcU28KGdaKjJiX5r6vw54WKGVcWu6jymSs3DULhaNdZlteeMKLI6RmC+RnJVJWevEiF7BapT2qctOlpy847bk7kDjkz+fpfNxNGSTyn0laaAW70SzAttYlweuhC5DZajaLhWG6NIDzZXgyrC99Ko4v/sE8DRg3XAP8QQwy5knwpR58XCzhvWL1k6QRHvMOxgeBE3yIUJmpApVXf0b04a7e1glG3ekN9HPjSOVqEsTQizAZOyGW7pNDWKbRZMZsFITd9LrtO4OXq2lD5FfPBKy+dtcjfp+4TiBlAvA+IM6rOQ== Received: from VE1EUR02FT003.eop-EUR02.prod.protection.outlook.com (10.152.12.55) by VE1EUR02HT150.eop-EUR02.prod.protection.outlook.com (10.152.13.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.14; Sun, 20 Oct 2019 12:08:33 +0000 Received: from DB7PR07MB4917.eurprd07.prod.outlook.com (10.152.12.58) by VE1EUR02FT003.mail.protection.outlook.com (10.152.12.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.14 via Frontend Transport; Sun, 20 Oct 2019 12:08:32 +0000 Received: from DB7PR07MB4917.eurprd07.prod.outlook.com ([fe80::1b8:f59a:96de:82ef]) by DB7PR07MB4917.eurprd07.prod.outlook.com ([fe80::1b8:f59a:96de:82ef%3]) with mapi id 15.20.2367.021; Sun, 20 Oct 2019 12:08:32 +0000 From: =?iso-8859-1?Q?Marvin_H=E4user?= To: "devel@edk2.groups.io" CC: "vit9696@protonmail.com" , Michael D Kinney , Liming Gao Subject: [PATCH] MdePkg/UefiFileHandleLib: Tolerate more Root handle FileNames Thread-Topic: [PATCH] MdePkg/UefiFileHandleLib: Tolerate more Root handle FileNames Thread-Index: AQHVhz8Xr8i6u+dL8k2RjSKLZZeeZQ== Date: Sun, 20 Oct 2019 12:08:32 +0000 Message-ID: References: In-Reply-To: Accept-Language: de-DE, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM0PR01CA0052.eurprd01.prod.exchangelabs.com (2603:10a6:208:e6::29) To DB7PR07MB4917.eurprd07.prod.outlook.com (2603:10a6:10:5f::30) x-incomingtopheadermarker: OriginalChecksum:732F534A713E11E224E24BD86133933743F1D7178AB22C576534FF68000A3BDE;UpperCasedChecksum:AAE94BADB8E0DA03CAC53D01A344553B4297749FE9AB27CF92D15B1529C02DC3;SizeAsReceived:7795;Count:51 x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0.windows.1 x-tmn: [0FW4TW5X7bbXldF3SXu7I1MQ2dgxxGSN] x-microsoft-original-message-id: x-ms-publictraffictype: Email x-incomingheadercount: 51 x-eopattributedmessage: 0 x-ms-traffictypediagnostic: VE1EUR02HT150: x-ms-exchange-purlcount: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: blXt7PgEn1fGacoMbsv4jQwbbWx6vOBXu6382memqSoa/LZxW4xfG6BXxqBCyqnaC+Da0iXqGhabxSRCg13/aWaMgQ7zs3ODVo4TbUDYAicoEjfNianLAfcVwm+454K3TVmSUcfWqtNBGKtIa5ztGnpN//RA3TEOG89UMR9b691cCg2J/MQzJYgY5xVRobafzoqZ8DxhMJlEdHp2Iiw9/d92vrRo+AIqLL0vzyJ6f9Q= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 786c0dbb-244b-4de3-7015-08d7555639f5 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Oct 2019 12:08:32.8321 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR02HT150 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable From: Marvin Haeuser REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2295 The current implementation of the FileHandleGetFileName() function assumes that the Root directory always has the FileName '\0'. However, the only requirement the UEFI specification defines is that a prepended '\\' must be supported to access files and folders relative to the Root directory. This patch removes this assumption and supports constructing valid paths for any value of FileName for the Root Directory. In practice, this fixes compatibility issues with File System drivers that report '\\' as the FileName of the Root directory, which currently is both generating an invalid path ("\\\\") and resulting in an EFI_NOT_FOUND result from the CurrentHandle->Open() call. Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Marvin Haeuser --- MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c | 25 ++++++++++++++--= ---- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c b/MdePkg/= Library/UefiFileHandleLib/UefiFileHandleLib.c index 5dc893833a46..28e28e5f67d5 100644 --- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c +++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c @@ -816,10 +816,25 @@ FileHandleGetFileName ( Status =3D EFI_OUT_OF_RESOURCES;=0D break;=0D } else {=0D + //=0D + // Prepare to move to the parent directory.=0D + // Also determine whether CurrentHandle refers to the Root directo= ry.=0D + //=0D + Status =3D CurrentHandle->Open (CurrentHandle, &NextHigherHandle, = L"..", EFI_FILE_MODE_READ, 0);=0D //=0D // We got info... do we have a name? if yes precede the current pa= th with it...=0D //=0D - if (StrLen (FileInfo->FileName) =3D=3D 0) {=0D + if ((StrLen (FileInfo->FileName) =3D=3D 0) || EFI_ERROR (Status)) = {=0D + //=0D + // Both FileInfo->FileName being '\0' and EFI_ERROR() suggest th= at=0D + // CurrentHandle refers to the Root directory. As this loop ens= ures=0D + // FullFileName is starting with '\\' at all times, signal succe= ss=0D + // and exit the loop.=0D + // While FileInfo->FileName could theoretically be a value other= than=0D + // '\0' or '\\', '\\' is guaranteed to be supported by the=0D + // specification and hence its value can safely be ignored.=0D + //=0D + Status =3D EFI_SUCCESS;=0D if (*FullFileName =3D=3D NULL) {=0D ASSERT((*FullFileName =3D=3D NULL && Size =3D=3D 0) || (*FullF= ileName !=3D NULL));=0D *FullFileName =3D StrnCatGrowLeft(FullFileName, &Size, L"\\", = 0);=0D @@ -837,15 +852,11 @@ FileHandleGetFileName ( FreePool(FileInfo);=0D }=0D }=0D +=0D + FileHandleClose(CurrentHandle);=0D //=0D // Move to the parent directory=0D //=0D - Status =3D CurrentHandle->Open (CurrentHandle, &NextHigherHandle, L"= ..", EFI_FILE_MODE_READ, 0);=0D - if (EFI_ERROR (Status)) {=0D - break;=0D - }=0D -=0D - FileHandleClose(CurrentHandle);=0D CurrentHandle =3D NextHigherHandle;=0D }=0D } else if (Status =3D=3D EFI_NOT_FOUND) {=0D --=20 2.23.0.windows.1