]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/BaseLib: Fix PathCleanUpDirectories to correctly handle "\.\"
authorRuiyu Ni <ruiyu.ni@intel.com>
Wed, 21 Dec 2016 07:21:32 +0000 (15:21 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Thu, 29 Dec 2016 01:32:44 +0000 (09:32 +0800)
The old code incorrectly cleans path like "fs0:\abc\.\.." to
"fs0:\abc", instead of "fs0:\"

The patch fixes this bug.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
MdePkg/Library/BaseLib/FilePaths.c

index 29a84ea9025cc010986a8d1522eb00cc3c564709..203045ccdc8f253f564e26eaea21670acc1c35a3 100644 (file)
@@ -68,61 +68,51 @@ CHAR16*
 EFIAPI\r
 PathCleanUpDirectories(\r
   IN CHAR16 *Path\r
-  )\r
+)\r
 {\r
   CHAR16  *TempString;\r
-  UINTN   TempSize;\r
 \r
-  if (Path==NULL) {\r
-    return(NULL);\r
+  if (Path == NULL) {\r
+    return NULL;\r
   }\r
+\r
   //\r
-  // Fix up the '/' vs '\'\r
+  // Replace the '/' with '\'\r
   //\r
-  for (TempString = Path ; TempString != NULL && *TempString != CHAR_NULL ; TempString++) {\r
+  for (TempString = Path; *TempString != CHAR_NULL; TempString++) {\r
     if (*TempString == L'/') {\r
       *TempString = L'\\';\r
     }\r
   }\r
+\r
   //\r
-  // Fix up the ..\r
+  // Remove all the "\.". E.g.: fs0:\abc\.\def\.\r
   //\r
-  while ((TempString = StrStr(Path, L"\\..\\")) != NULL) {\r
-    *TempString = CHAR_NULL;\r
-    TempString  += 4;\r
-    PathRemoveLastItem(Path);\r
-    TempSize = StrSize(TempString);\r
-    CopyMem(Path+StrLen(Path), TempString, TempSize);\r
+  while ((TempString = StrStr (Path, L"\\.\\")) != NULL) {\r
+    CopyMem (TempString, TempString + 2, StrSize (TempString + 2));\r
   }\r
-  if ((TempString = StrStr(Path, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) {\r
-    *TempString = CHAR_NULL;\r
-    if (!PathRemoveLastItem(Path)) {\r
-      *TempString = L'\\';\r
-    }\r
+  if (StrCmp (Path + StrLen (Path) - 2, L"\\.") == 0) {\r
+    Path[StrLen (Path) - 1] = CHAR_NULL;\r
   }\r
+\r
   //\r
-  // Fix up the .\r
+  // Remove all the "\..". E.g.: fs0:\abc\..\def\..\r
   //\r
-  while ((TempString = StrStr(Path, L"\\.\\")) != NULL) {\r
-    *TempString = CHAR_NULL;\r
-    TempString  += 2;\r
-    TempSize = StrSize(TempString);\r
-    CopyMem(Path+StrLen(Path), TempString, TempSize);\r
-  }\r
-  if ((TempString = StrStr(Path, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {\r
+  while (((TempString = StrStr(Path, L"\\..")) != NULL) &&\r
+         ((*(TempString + 3) == L'\\') || (*(TempString + 3) == CHAR_NULL))\r
+        ) {\r
     *(TempString + 1) = CHAR_NULL;\r
+    PathRemoveLastItem(Path);\r
+    CopyMem (Path + StrLen (Path), TempString + 3, StrSize (TempString + 3));\r
   }\r
 \r
-  while ((TempString = StrStr(Path, L"\\\\")) != NULL) {\r
-    *TempString = CHAR_NULL;\r
-    TempString  += 1;\r
-    TempSize = StrSize(TempString);\r
-    CopyMem(Path+StrLen(Path), TempString, TempSize);\r
-  }\r
-  if ((TempString = StrStr(Path, L"\\\\")) != NULL && *(TempString + 1) == CHAR_NULL) {\r
-    *(TempString) = CHAR_NULL;\r
+  //\r
+  // Replace the "\\" with "\"\r
+  //\r
+  while ((TempString = StrStr (Path, L"\\\\")) != NULL) {\r
+    CopyMem (TempString, TempString + 1, StrSize (TempString + 1));\r
   }\r
 \r
-  return (Path);\r
+  return Path;\r
 }\r
 \r