]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
MdePkg/UefiFileHandleLib: Tolerate more Root handle FileNames
[mirror_edk2.git] / MdePkg / Library / UefiFileHandleLib / UefiFileHandleLib.c
index 5dc893833a4667492ee33d0ae4643025f514ac24..28e28e5f67d5bc4d6cb81663b28c43470a26c2e0 100644 (file)
@@ -816,10 +816,25 @@ FileHandleGetFileName (
         Status = EFI_OUT_OF_RESOURCES;\r
         break;\r
       } else {\r
+        //\r
+        // Prepare to move to the parent directory.\r
+        // Also determine whether CurrentHandle refers to the Root directory.\r
+        //\r
+        Status = CurrentHandle->Open (CurrentHandle, &NextHigherHandle, L"..", EFI_FILE_MODE_READ, 0);\r
         //\r
         // We got info... do we have a name? if yes precede the current path with it...\r
         //\r
-        if (StrLen (FileInfo->FileName) == 0) {\r
+        if ((StrLen (FileInfo->FileName) == 0) || EFI_ERROR (Status)) {\r
+          //\r
+          // Both FileInfo->FileName being '\0' and EFI_ERROR() suggest that\r
+          // CurrentHandle refers to the Root directory.  As this loop ensures\r
+          // FullFileName is starting with '\\' at all times, signal success\r
+          // and exit the loop.\r
+          // While FileInfo->FileName could theoretically be a value other than\r
+          // '\0' or '\\', '\\' is guaranteed to be supported by the\r
+          // specification and hence its value can safely be ignored.\r
+          //\r
+          Status = EFI_SUCCESS;\r
           if (*FullFileName == NULL) {\r
             ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));\r
             *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);\r
@@ -837,15 +852,11 @@ FileHandleGetFileName (
           FreePool(FileInfo);\r
         }\r
       }\r
+\r
+      FileHandleClose(CurrentHandle);\r
       //\r
       // Move to the parent directory\r
       //\r
-      Status = CurrentHandle->Open (CurrentHandle, &NextHigherHandle, L"..", EFI_FILE_MODE_READ, 0);\r
-      if (EFI_ERROR (Status)) {\r
-        break;\r
-      }\r
-\r
-      FileHandleClose(CurrentHandle);\r
       CurrentHandle = NextHigherHandle;\r
     }\r
   } else if (Status == EFI_NOT_FOUND) {\r