From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web12.1542.1571885520253734116 for ; Wed, 23 Oct 2019 19:52:00 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: zhichao.gao@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Oct 2019 19:51:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,222,1569308400"; d="scan'208";a="192041057" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga008.jf.intel.com with ESMTP; 23 Oct 2019 19:51:53 -0700 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 23 Oct 2019 19:51:35 -0700 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 23 Oct 2019 19:51:35 -0700 Received: from shsmsx153.ccr.corp.intel.com (10.239.6.53) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Wed, 23 Oct 2019 19:51:35 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.96]) by SHSMSX153.ccr.corp.intel.com ([10.239.6.53]) with mapi id 14.03.0439.000; Thu, 24 Oct 2019 10:51:33 +0800 From: "Gao, Zhichao" 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 Thread-Topic: [PATCH] MdePkg/UefiFileHandleLib: Tolerate more Root handle FileNames Thread-Index: AQHVhz8Xr8i6u+dL8k2RjSKLZZeeZadpGp7g Date: Thu, 24 Oct 2019 02:51:33 +0000 Message-ID: <3CE959C139B4C44DBEA1810E3AA6F9000B85A759@SHSMSX101.ccr.corp.intel.com> References: In-Reply-To: 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: zhichao.gao@intel.com Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable This patch makes sense. The patch would not affect the original logic and f= igure 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 >=20 > From: Marvin Haeuser >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2295 >=20 > 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. >=20 > In practice, this fixes compatibility issues with File System drivers th= at report > '\\' as the FileName of the Root directory, which currently is both gene= rating > an invalid path ("\\\\") and resulting in an EFI_NOT_FOUND result from t= he > CurrentHandle->Open() call. >=20 > 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(-) >=20 > 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 dire= ctory. > + // > + Status =3D CurrentHandle->Open (CurrentHandle, &NextHigherHandl= e, > + L"..", EFI_FILE_MODE_READ, 0); > // > // We got info... do we have a name? if yes precede the current= path > with it... > // > - if (StrLen (FileInfo->FileName) =3D=3D 0) { > + if ((StrLen (FileInfo->FileName) =3D=3D 0) || EFI_ERROR (Status= )) { > + // > + // Both FileInfo->FileName being '\0' and EFI_ERROR() suggest= that > + // CurrentHandle refers to the Root directory. As this loop = ensures > + // FullFileName is starting with '\\' at all times, signal su= ccess > + // and exit the loop. > + // While FileInfo->FileName could theoretically be a value ot= her 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) || (*Fu= llFileName !=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 >=20 >=20