summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library/UefiFileHandleLib
diff options
context:
space:
mode:
authorMarvin Haeuser <mhaeuser@outlook.de>2019-10-20 20:08:32 +0800
committerLiming Gao <liming.gao@intel.com>2019-11-04 08:52:57 +0800
commit6407186db9505f101ece4e1571eceed69b9fbdbe (patch)
treebf09665dad41852219a8194765c0d3ccf0a9eacf /MdePkg/Library/UefiFileHandleLib
parent1009b59b6525c16724fe2684c344a6359af28b55 (diff)
downloadedk2-6407186db9505f101ece4e1571eceed69b9fbdbe.tar.gz
edk2-6407186db9505f101ece4e1571eceed69b9fbdbe.tar.bz2
edk2-6407186db9505f101ece4e1571eceed69b9fbdbe.zip
MdePkg/UefiFileHandleLib: Tolerate more Root handle FileNames
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2295 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 <michael.d.kinney@intel.com> Cc: Liming Gao <liming.gao@intel.com> Signed-off-by: Marvin Haeuser <mhaeuser@outlook.de> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
Diffstat (limited to 'MdePkg/Library/UefiFileHandleLib')
-rw-r--r--MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
index 5dc893833a..28e28e5f67 100644
--- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
+++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
@@ -817,9 +817,24 @@ FileHandleGetFileName (
break;
} else {
//
+ // Prepare to move to the parent directory.
+ // Also determine whether CurrentHandle refers to the Root directory.
+ //
+ Status = CurrentHandle->Open (CurrentHandle, &NextHigherHandle, 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) == 0) {
+ if ((StrLen (FileInfo->FileName) == 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 success
+ // and exit the loop.
+ // While FileInfo->FileName could theoretically be a value other than
+ // '\0' or '\\', '\\' is guaranteed to be supported by the
+ // specification and hence its value can safely be ignored.
+ //
+ Status = EFI_SUCCESS;
if (*FullFileName == NULL) {
ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
*FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
@@ -837,15 +852,11 @@ FileHandleGetFileName (
FreePool(FileInfo);
}
}
+
+ FileHandleClose(CurrentHandle);
//
// Move to the parent directory
//
- Status = CurrentHandle->Open (CurrentHandle, &NextHigherHandle, L"..", EFI_FILE_MODE_READ, 0);
- if (EFI_ERROR (Status)) {
- break;
- }
-
- FileHandleClose(CurrentHandle);
CurrentHandle = NextHigherHandle;
}
} else if (Status == EFI_NOT_FOUND) {