summaryrefslogtreecommitdiffstats
path: root/ShellPkg/Library/UefiShellLevel2CommandsLib
diff options
context:
space:
mode:
authorChen A Chen <chen.a.chen@intel.com>2016-11-22 16:16:02 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2016-12-05 09:18:32 +0800
commit0db4acb61ac4e79a8a95b0e82874e8b6bed8e4bb (patch)
treea602ef755972df389d7aee8dd5c9cad4a906eb53 /ShellPkg/Library/UefiShellLevel2CommandsLib
parent7bbe0b3eff9e7876808ce1b96b9a71360984cf91 (diff)
downloadedk2-0db4acb61ac4e79a8a95b0e82874e8b6bed8e4bb.tar.gz
edk2-0db4acb61ac4e79a8a95b0e82874e8b6bed8e4bb.tar.bz2
edk2-0db4acb61ac4e79a8a95b0e82874e8b6bed8e4bb.zip
ShellPkg/MV: Fix MV to deny moving parent of current directory
When user types "mv -r fs0:\A\ fs1:\" under directory "fs0:\A\B\", MV command should deny such movement. The patch fixes the above issue. It also denies moving current directory. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Chen A Chen <chen.a.chen@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Diffstat (limited to 'ShellPkg/Library/UefiShellLevel2CommandsLib')
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c81
1 files changed, 75 insertions, 6 deletions
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
index efaaeb2d7b..71e43367c6 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
@@ -58,6 +58,73 @@ IsBetweenFileSystem(
}
/**
+ function to determine if SrcPath is valid to mv.
+
+ if SrcPath equal CWD then it's invalid.
+ if SrcPath is the parent path of CWD then it's invalid.
+ is SrcPath is NULL return FALSE.
+
+ if CwdPath is NULL then ASSERT()
+
+ @param SrcPath [in] The source path.
+ @param CwdPath [in] The current working directory.
+
+ @retval TRUE The source path is valid.
+ @retval FALSE The source path is invalid.
+**/
+BOOLEAN
+IsSoucePathValid(
+ IN CONST CHAR16* SrcPath,
+ IN CONST CHAR16* CwdPath
+ )
+{
+ CHAR16* SrcPathBuffer;
+ CHAR16* CwdPathBuffer;
+ BOOLEAN Ret;
+
+ ASSERT (CwdPath != NULL);
+ if (SrcPath == NULL) {
+ return FALSE;
+ }
+
+ Ret = TRUE;
+
+ SrcPathBuffer = AllocateCopyPool (StrSize (SrcPath), SrcPath);
+ if (SrcPathBuffer == NULL) {
+ return FALSE;
+ }
+
+ CwdPathBuffer = AllocateCopyPool (StrSize (CwdPath), CwdPath);
+ if (CwdPathBuffer == NULL) {
+ FreePool(SrcPathBuffer);
+ return FALSE;
+ }
+
+ gUnicodeCollation->StrUpr (gUnicodeCollation, SrcPathBuffer);
+ gUnicodeCollation->StrUpr (gUnicodeCollation, CwdPathBuffer);
+
+ if (SrcPathBuffer[StrLen (SrcPathBuffer) -1 ] == L'\\') {
+ SrcPathBuffer[StrLen (SrcPathBuffer) - 1] = CHAR_NULL;
+ }
+
+ if (CwdPathBuffer[StrLen (CwdPathBuffer) - 1] == L'\\') {
+ CwdPathBuffer[StrLen (CwdPathBuffer) - 1] = CHAR_NULL;
+ }
+
+ if (StrCmp (CwdPathBuffer, SrcPathBuffer) == 0 ||
+ ((StrStr (CwdPathBuffer, SrcPathBuffer) == CwdPathBuffer) &&
+ (CwdPathBuffer[StrLen (SrcPathBuffer)] == L'\\'))
+ ) {
+ Ret = FALSE;
+ }
+
+ FreePool (SrcPathBuffer);
+ FreePool (CwdPathBuffer);
+
+ return Ret;
+}
+
+/**
Function to validate that moving a specific file (FileName) to a specific
location (DestPath) is valid.
@@ -90,12 +157,14 @@ IsValidMove(
CHAR16 *DestPathCopy;
CHAR16 *DestPathWalker;
- if (Cwd != NULL && StrCmp(SourcePath, Cwd) == 0) {
- //
- // Invalid move
- //
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_CWD), gShellLevel2HiiHandle);
- return (FALSE);
+ if ((Cwd != NULL) && ((Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY)) {
+ if (!IsSoucePathValid (SourcePath, Cwd)) {
+ //
+ // Invalid move
+ //
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_MV_INV_CWD), gShellLevel2HiiHandle);
+ return FALSE;
+ }
}
//