From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AA555822B8 for ; Wed, 21 Dec 2016 00:55:06 -0800 (PST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP; 21 Dec 2016 00:55:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,382,1477983600"; d="scan'208";a="45281515" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by fmsmga005.fm.intel.com with ESMTP; 21 Dec 2016 00:55:05 -0800 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Chen A Chen , Jaben Carsey Date: Wed, 21 Dec 2016 16:55:00 +0800 Message-Id: <20161221085501.159796-2-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20161221085501.159796-1-ruiyu.ni@intel.com> References: <20161221085501.159796-1-ruiyu.ni@intel.com> Subject: [PATCH 1/2] MdePkg/BaseLib: Fix PathCleanUpDirectories to correctly handle "\.\" X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Dec 2016 08:55:06 -0000 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 Signed-off-by: Ruiyu Ni Cc: Jaben Carsey --- 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