]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
1.Add code to check the pointer 'CorrectedPath' in Ls.c line 460 before referenced...
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Mv.c
index 5afcea23107fd62d9955d4447eaa171b25dfa170..65e83ccc0f4336130f150df627acb0fec860a577 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Main file for mv shell level 2 function.\r
 \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2013, Hewlett-Packard Development Company, L.P.\r
+  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -116,13 +117,14 @@ IsValidMove(
 \r
   if the result is sucessful the caller must free *DestPathPointer.\r
 \r
-  @param[in] DestDir              The original path to the destination.\r
-  @param[in,out] DestPathPointer  A pointer to the callee allocated final path.\r
-  @param[in] Cwd                  A pointer to the current working directory.\r
+  @param[in] DestDir               The original path to the destination.\r
+  @param[in, out] DestPathPointer  A pointer to the callee allocated final path.\r
+  @param[in] Cwd                   A pointer to the current working directory.\r
 \r
-  @retval EFI_INVALID_PARAMETR  The DestDir could not be resolved to a location.\r
-  @retval EFI_INVALID_PARAMETR  The DestDir could be resolved to more than 1 location.\r
-  @retval EFI_SUCCESS           The operation was sucessful.\r
+  @retval SHELL_INVALID_PARAMETER  The DestDir could not be resolved to a location.\r
+  @retval SHELL_INVALID_PARAMETER  The DestDir could be resolved to more than 1 location.\r
+  @retval SHELL_INVALID_PARAMETER  Cwd is required and is NULL.\r
+  @retval SHELL_SUCCESS            The operation was sucessful.\r
 **/\r
 SHELL_STATUS\r
 EFIAPI\r
@@ -134,33 +136,46 @@ GetDestinationLocation(
 {\r
   EFI_SHELL_FILE_INFO       *DestList;\r
   EFI_SHELL_FILE_INFO       *Node;\r
-  EFI_STATUS                Status;\r
   CHAR16                    *DestPath;\r
-  CHAR16                    *TempLocation;\r
   UINTN                     NewSize;\r
+  UINTN                     CurrentSize;\r
 \r
   DestList = NULL;\r
   DestPath = NULL;\r
 \r
   if (StrStr(DestDir, L"\\") == DestDir) {\r
+    if (Cwd == NULL) {\r
+      return SHELL_INVALID_PARAMETER;\r
+    }\r
     DestPath = AllocateZeroPool(StrSize(Cwd));\r
     if (DestPath == NULL) {\r
       return (SHELL_OUT_OF_RESOURCES);\r
     }\r
     StrCpy(DestPath, Cwd);\r
     while (PathRemoveLastItem(DestPath)) ;\r
+\r
+    //\r
+    // Append DestDir beyond '\' which may be present\r
+    //\r
+    CurrentSize = StrSize(DestPath);\r
+    StrnCatGrow(&DestPath, &CurrentSize, &DestDir[1], 0);\r
+\r
     *DestPathPointer =  DestPath;\r
     return (SHELL_SUCCESS);\r
   }\r
   //\r
   // get the destination path\r
   //\r
-  Status = ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, &DestList);\r
+  ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, &DestList);\r
   if (DestList == NULL || IsListEmpty(&DestList->Link)) {\r
     //\r
     // Not existing... must be renaming\r
     //\r
-    if ((TempLocation = StrStr(DestDir, L":")) == NULL) {\r
+    if (StrStr(DestDir, L":") == NULL) {\r
+      if (Cwd == NULL) {\r
+        ShellCloseFileMetaArg(&DestList);\r
+        return (SHELL_INVALID_PARAMETER);\r
+      }\r
       NewSize = StrSize(Cwd);\r
       NewSize += StrSize(DestDir);\r
       DestPath = AllocateZeroPool(NewSize);\r
@@ -316,13 +331,13 @@ ValidateAndMoveFiles(
     // construct the new file info block\r
     //\r
     NewSize = StrSize(DestPath);\r
-    NewSize += StrSize(Node->FileName) + sizeof(EFI_FILE_INFO) + sizeof(CHAR16);\r
+    NewSize += StrSize(Node->FileName) + SIZE_OF_EFI_FILE_INFO + sizeof(CHAR16);\r
     NewFileInfo = AllocateZeroPool(NewSize);\r
     if (NewFileInfo == NULL) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);\r
       ShellStatus = SHELL_OUT_OF_RESOURCES;\r
     } else {\r
-      CopyMem(NewFileInfo, Node->Info, sizeof(EFI_FILE_INFO));\r
+      CopyMem(NewFileInfo, Node->Info, SIZE_OF_EFI_FILE_INFO);\r
       if (DestPath[0] != L'\\') {\r
         StrCpy(NewFileInfo->FileName, L"\\");\r
         StrCat(NewFileInfo->FileName, DestPath);\r
@@ -342,7 +357,7 @@ ValidateAndMoveFiles(
         }\r
         StrCat(NewFileInfo->FileName, Node->FileName);\r
       }\r
-      NewFileInfo->Size = sizeof(EFI_FILE_INFO) + StrSize(NewFileInfo->FileName);\r
+      NewFileInfo->Size = SIZE_OF_EFI_FILE_INFO + StrSize(NewFileInfo->FileName);\r
       ShellPrintEx(-1, -1, HiiOutput, Node->FullName, NewFileInfo->FileName);\r
 \r
       if (!EFI_ERROR(ShellFileExists(NewFileInfo->FileName))) {\r
@@ -397,23 +412,18 @@ ValidateAndMoveFiles(
       //\r
       if (EFI_ERROR(Status)) {\r
         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);\r
-        //\r
-        // move failed\r
-        //\r
-        switch(Status){\r
-          default:\r
-            ShellStatus = SHELL_INVALID_PARAMETER;\r
-          case EFI_SECURITY_VIOLATION:\r
-            ShellStatus = SHELL_SECURITY_VIOLATION;\r
-          case EFI_WRITE_PROTECTED:\r
-            ShellStatus = SHELL_WRITE_PROTECTED;\r
-          case EFI_OUT_OF_RESOURCES:\r
-            ShellStatus = SHELL_OUT_OF_RESOURCES;\r
-          case EFI_DEVICE_ERROR:\r
-            ShellStatus = SHELL_DEVICE_ERROR;\r
-          case EFI_ACCESS_DENIED:\r
-            ShellStatus = SHELL_ACCESS_DENIED;\r
-        } // switch\r
+        ShellStatus = SHELL_INVALID_PARAMETER;\r
+        if (Status == EFI_SECURITY_VIOLATION) {\r
+          ShellStatus = SHELL_SECURITY_VIOLATION;\r
+        } else if (Status == EFI_WRITE_PROTECTED) {\r
+          ShellStatus = SHELL_WRITE_PROTECTED;\r
+        } else if (Status == EFI_OUT_OF_RESOURCES) {\r
+          ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+        } else if (Status == EFI_DEVICE_ERROR) {\r
+          ShellStatus = SHELL_DEVICE_ERROR;\r
+        } else if (Status == EFI_ACCESS_DENIED) {\r
+          ShellStatus = SHELL_ACCESS_DENIED;\r
+        }\r
       } else {\r
         ShellPrintEx(-1, -1, L"%s", HiiResultOk);\r
       }\r