From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Chen A Chen <chen.a.chen@intel.com>,
Jaben Carsey <jaben.carsey@intel.com>
Subject: [PATCH 1/2] MdePkg/BaseLib: Fix PathCleanUpDirectories to correctly handle "\.\"
Date: Wed, 21 Dec 2016 16:55:00 +0800 [thread overview]
Message-ID: <20161221085501.159796-2-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20161221085501.159796-1-ruiyu.ni@intel.com>
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>
Cc: Jaben Carsey <jaben.carsey@intel.com>
---
MdePkg/Library/BaseLib/FilePaths.c | 60 ++++++++++++++++----------------------
1 file changed, 25 insertions(+), 35 deletions(-)
diff --git a/MdePkg/Library/BaseLib/FilePaths.c b/MdePkg/Library/BaseLib/FilePaths.c
index 29a84ea..203045c 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;
}
--
2.9.0.windows.1
next prev parent reply other threads:[~2016-12-21 8:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-21 8:54 [PATCH 0/2] ShellPkg/cd: Fix "cd" to support "fs0:dir" (no slash after ':') Ruiyu Ni
2016-12-21 8:55 ` Ruiyu Ni [this message]
2016-12-21 8:55 ` [PATCH 2/2] " Ruiyu Ni
2016-12-21 16:23 ` Carsey, Jaben
2016-12-23 5:43 ` Ni, Ruiyu
2016-12-27 23:01 ` Carsey, Jaben
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161221085501.159796-2-ruiyu.ni@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox