From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.9893.1572828608014120606 for ; Sun, 03 Nov 2019 16:50:08 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: liming.gao@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Nov 2019 16:50:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,265,1569308400"; d="scan'208";a="212205409" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga001.fm.intel.com with ESMTP; 03 Nov 2019 16:50:07 -0800 Received: from shsmsx153.ccr.corp.intel.com (10.239.6.53) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 3 Nov 2019 16:50:07 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.127]) by SHSMSX153.ccr.corp.intel.com ([169.254.12.215]) with mapi id 14.03.0439.000; Mon, 4 Nov 2019 08:50:05 +0800 From: "Liming Gao" To: "Gao, Zhichao" , "devel@edk2.groups.io" , "Marvin.Haeuser@outlook.com" CC: "vit9696@protonmail.com" , "Kinney, Michael D" Subject: Re: [PATCH] MdePkg/UefiFileHandleLib: Tolerate more Root handle FileNames Thread-Topic: [PATCH] MdePkg/UefiFileHandleLib: Tolerate more Root handle FileNames Thread-Index: AQHVhz8Xr8i6u+dL8k2RjSKLZZeeZadpGp7ggBEqbsA= Date: Mon, 4 Nov 2019 00:50:04 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E536709@SHSMSX104.ccr.corp.intel.com> References: <3CE959C139B4C44DBEA1810E3AA6F9000B85A759@SHSMSX101.ccr.corp.intel.com> In-Reply-To: <3CE959C139B4C44DBEA1810E3AA6F9000B85A759@SHSMSX101.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: liming.gao@intel.com Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao >-----Original Message----- >From: Gao, Zhichao >Sent: Thursday, October 24, 2019 10:52 AM >To: devel@edk2.groups.io; Marvin.Haeuser@outlook.com >Cc: vit9696@protonmail.com; Kinney, Michael D >; Gao, Liming >Subject: RE: [PATCH] MdePkg/UefiFileHandleLib: Tolerate more Root handle >FileNames > >This patch makes sense. The patch would not affect the original logic and >figure out the failure if the root directory file name is '\\'. >Reviewed-by: Zhichao Gao > >> -----Original Message----- >> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of >> Marvin H=E4user >> Sent: Sunday, October 20, 2019 8:09 PM >> To: devel@edk2.groups.io >> Cc: vit9696@protonmail.com; Kinney, Michael D >> ; Gao, Liming >> Subject: [edk2-devel] [PATCH] MdePkg/UefiFileHandleLib: Tolerate more >> Root handle FileNames >> >> 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 t= o the >> Root directory. >> This patch removes this assumption and supports constructing valid path= s >for >> any value of FileName for the Root Directory. >> >> In practice, this fixes compatibility issues with File System drivers t= hat report >> '\\' as the FileName of the Root directory, which currently is both gen= erating >> 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; >> break; >> } else { >> + // >> + // Prepare to move to the parent directory. >> + // Also determine whether CurrentHandle refers to the Root dir= ectory. >> + // >> + Status =3D CurrentHandle->Open (CurrentHandle, &NextHigherHand= le, >> + L"..", EFI_FILE_MODE_READ, 0); >> // >> // We got info... do we have a name? if yes precede the curren= t path >> with it... >> // >> - if (StrLen (FileInfo->FileName) =3D=3D 0) { >> + if ((StrLen (FileInfo->FileName) =3D=3D 0) || EFI_ERROR (Statu= s)) { >> + // >> + // Both FileInfo->FileName being '\0' and EFI_ERROR() sugges= t that >> + // CurrentHandle refers to the Root directory. As this loop= ensures >> + // FullFileName is starting with '\\' at all times, signal s= uccess >> + // and exit the loop. >> + // While FileInfo->FileName could theoretically be a value o= ther than >> + // '\0' or '\\', '\\' is guaranteed to be supported by the >> + // specification and hence its value can safely be ignored. >> + // >> + Status =3D EFI_SUCCESS; >> if (*FullFileName =3D=3D NULL) { >> ASSERT((*FullFileName =3D=3D NULL && Size =3D=3D 0) || (*F= ullFileName !=3D >> NULL)); >> *FullFileName =3D StrnCatGrowLeft(FullFileName, &Size, L"\= \", 0); @@ - >> 837,15 +852,11 @@ FileHandleGetFileName ( >> FreePool(FileInfo); >> } >> } >> + >> + FileHandleClose(CurrentHandle); >> // >> // Move to the parent directory >> // >> - Status =3D CurrentHandle->Open (CurrentHandle, &NextHigherHandle= , >> L"..", EFI_FILE_MODE_READ, 0); >> - if (EFI_ERROR (Status)) { >> - break; >> - } >> - >> - FileHandleClose(CurrentHandle); >> CurrentHandle =3D NextHigherHandle; >> } >> } else if (Status =3D=3D EFI_NOT_FOUND) { >> -- >> 2.23.0.windows.1 >> >> >>=20