summaryrefslogtreecommitdiffstats
path: root/MdePkg
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2016-12-21 15:21:32 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2016-12-29 09:32:44 +0800
commitbb99e3282c9e69fbd6365d117c58d15589e34c5d (patch)
tree1734d39f6b08236b7a690e4c4013f9069ee1763d /MdePkg
parentaf8ba51aca4e0b41a359fe467fb5c5b9baa75a05 (diff)
downloadedk2-bb99e3282c9e69fbd6365d117c58d15589e34c5d.tar.gz
edk2-bb99e3282c9e69fbd6365d117c58d15589e34c5d.tar.bz2
edk2-bb99e3282c9e69fbd6365d117c58d15589e34c5d.zip
MdePkg/BaseLib: Fix PathCleanUpDirectories to correctly handle "\.\"
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>
Diffstat (limited to 'MdePkg')
-rw-r--r--MdePkg/Library/BaseLib/FilePaths.c60
1 files changed, 25 insertions, 35 deletions
diff --git a/MdePkg/Library/BaseLib/FilePaths.c b/MdePkg/Library/BaseLib/FilePaths.c
index 29a84ea902..203045ccdc 100644
--- a/MdePkg/Library/BaseLib/FilePaths.c
+++ b/MdePkg/Library/BaseLib/FilePaths.c
@@ -68,61 +68,51 @@ CHAR16*
EFIAPI
PathCleanUpDirectories(
IN CHAR16 *Path
- )
+)
{
CHAR16 *TempString;
- UINTN TempSize;
- if (Path==NULL) {
- return(NULL);
+ if (Path == NULL) {
+ return NULL;
}
+
//
- // Fix up the '/' vs '\'
+ // Replace the '/' with '\'
//
- for (TempString = Path ; TempString != NULL && *TempString != CHAR_NULL ; TempString++) {
+ for (TempString = Path; *TempString != CHAR_NULL; TempString++) {
if (*TempString == L'/') {
*TempString = L'\\';
}
}
+
//
- // Fix up the ..
+ // Remove all the "\.". E.g.: fs0:\abc\.\def\.
//
- while ((TempString = StrStr(Path, L"\\..\\")) != NULL) {
- *TempString = CHAR_NULL;
- TempString += 4;
- PathRemoveLastItem(Path);
- TempSize = StrSize(TempString);
- CopyMem(Path+StrLen(Path), TempString, TempSize);
+ while ((TempString = StrStr (Path, L"\\.\\")) != NULL) {
+ CopyMem (TempString, TempString + 2, StrSize (TempString + 2));
}
- if ((TempString = StrStr(Path, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) {
- *TempString = CHAR_NULL;
- if (!PathRemoveLastItem(Path)) {
- *TempString = L'\\';
- }
+ if (StrCmp (Path + StrLen (Path) - 2, L"\\.") == 0) {
+ Path[StrLen (Path) - 1] = CHAR_NULL;
}
+
//
- // Fix up the .
+ // Remove all the "\..". E.g.: fs0:\abc\..\def\..
//
- while ((TempString = StrStr(Path, L"\\.\\")) != NULL) {
- *TempString = CHAR_NULL;
- TempString += 2;
- TempSize = StrSize(TempString);
- CopyMem(Path+StrLen(Path), TempString, TempSize);
- }
- if ((TempString = StrStr(Path, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {
+ while (((TempString = StrStr(Path, L"\\..")) != NULL) &&
+ ((*(TempString + 3) == L'\\') || (*(TempString + 3) == CHAR_NULL))
+ ) {
*(TempString + 1) = CHAR_NULL;
+ PathRemoveLastItem(Path);
+ CopyMem (Path + StrLen (Path), TempString + 3, StrSize (TempString + 3));
}
- while ((TempString = StrStr(Path, L"\\\\")) != NULL) {
- *TempString = CHAR_NULL;
- TempString += 1;
- TempSize = StrSize(TempString);
- CopyMem(Path+StrLen(Path), TempString, TempSize);
- }
- if ((TempString = StrStr(Path, L"\\\\")) != NULL && *(TempString + 1) == CHAR_NULL) {
- *(TempString) = CHAR_NULL;
+ //
+ // Replace the "\\" with "\"
+ //
+ while ((TempString = StrStr (Path, L"\\\\")) != NULL) {
+ CopyMem (TempString, TempString + 1, StrSize (TempString + 1));
}
- return (Path);
+ return Path;
}