]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
Cd - add more input verification.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Cp.c
index f15ff3030a65a362d970e8306f746add3e3a9fae..8c0bbce9aa021e2d15bc4636d17e9a23e2ffdcee 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for cp shell level 2 function.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2011, 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
 \r
 #include "UefiShellLevel2CommandsLib.h"\r
 \r
-// this is later in the file.\r
+/**\r
+  Function to take a list of files to copy and a destination location and do\r
+  the verification and copying of those files to that location.  This function\r
+  will report any errors to the user and halt.\r
+\r
+  @param[in] FileList           A LIST_ENTRY* based list of files to move.\r
+  @param[in] DestDir            The destination location.\r
+  @param[in] SilentMode         TRUE to eliminate screen output.\r
+  @param[in] RecursiveMode      TRUE to copy directories.\r
+  @param[in] Resp               The response to the overwrite query (if always).\r
+\r
+  @retval SHELL_SUCCESS             the files were all moved.\r
+  @retval SHELL_INVALID_PARAMETER   a parameter was invalid\r
+  @retval SHELL_SECURITY_VIOLATION  a security violation ocurred\r
+  @retval SHELL_WRITE_PROTECTED     the destination was write protected\r
+  @retval SHELL_OUT_OF_RESOURCES    a memory allocation failed\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 ValidateAndCopyFiles(\r
@@ -89,7 +105,7 @@ CopySingleFile(
   //\r
   if (!EFI_ERROR(Status)) {\r
     if (Response == NULL && !SilentMode) {\r
-      Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_CP_PROMPT), gShellLevel2HiiHandle, &Response);\r
+      Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);\r
     }\r
     //\r
     // possibly return based on response\r
@@ -191,8 +207,11 @@ CopySingleFile(
   The key is to have this function called ONLY once.  this allows for the parameter\r
   verification to happen correctly.\r
 \r
-  @param[in] FileList           A LIST_ENTRY* based list of files to move\r
-  @param[in] DestDir            the destination location\r
+  @param[in] FileList           A LIST_ENTRY* based list of files to move.\r
+  @param[in] DestDir            The destination location.\r
+  @param[in] SilentMode         TRUE to eliminate screen output.\r
+  @param[in] RecursiveMode      TRUE to copy directories.\r
+  @param[in] Resp               The response to the overwrite query (if always).\r
 \r
   @retval SHELL_SUCCESS             the files were all moved.\r
   @retval SHELL_INVALID_PARAMETER   a parameter was invalid\r
@@ -257,7 +276,7 @@ ValidateAndCopyFiles(
     }\r
 \r
     NewSize =  StrSize(DestDir);\r
-    NewSize += StrSize(Node->FileName);\r
+    NewSize += StrSize(Node->FullName);\r
     NewSize += StrSize(Cwd);\r
     if (NewSize > PathLen) {\r
       PathLen = NewSize;\r
@@ -285,7 +304,7 @@ ValidateAndCopyFiles(
 \r
   HiiOutput   = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_CP_OUTPUT), NULL);\r
   HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);\r
-  DestPath    = AllocatePool(PathLen);\r
+  DestPath    = AllocateZeroPool(PathLen);\r
 \r
   if (DestPath == NULL || HiiOutput == NULL || HiiResultOk == NULL) {\r
     SHELL_FREE_NON_NULL(DestPath);\r
@@ -317,17 +336,20 @@ ValidateAndCopyFiles(
     if (FileList->Link.ForwardLink == FileList->Link.BackLink // 1 item\r
       && EFI_ERROR(ShellIsDirectory(DestDir))                 // not an existing directory\r
      ) {\r
-      ASSERT(StrStr(DestDir, L":") == NULL);\r
-      //\r
-      // simple copy of a single file\r
-      //\r
-      StrCpy(DestPath, Cwd);\r
-      if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
-        StrCat(DestPath, L"\\");\r
-      } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
-        ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
+      if (StrStr(DestDir, L":") == NULL) {\r
+        //\r
+        // simple copy of a single file\r
+        //\r
+        StrCpy(DestPath, Cwd);\r
+        if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
+          StrCat(DestPath, L"\\");\r
+        } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
+          ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
+        }\r
+        StrCat(DestPath, DestDir);\r
+      } else {\r
+        StrCpy(DestPath, DestDir);\r
       }\r
-      StrCat(DestPath, DestDir);\r
     } else {\r
       //\r
       // we have multiple files or a directory in the DestDir\r
@@ -415,6 +437,18 @@ ValidateAndCopyFiles(
   return (ShellStatus);\r
 }\r
 \r
+/**\r
+  Validate and if successful copy all the files from the list into \r
+  destination directory.\r
+\r
+  @param[in] FileList       The list of files to copy.\r
+  @param[in] DestDir        The directory to copy files to.\r
+  @param[in] SilentMode     TRUE to eliminate screen output.\r
+  @param[in] RecursiveMode  TRUE to copy directories.\r
+\r
+  @retval SHELL_INVALID_PARAMETER   A parameter was invalid.\r
+  @retval SHELL_SUCCESS             The operation was successful.\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 ProcessValidateAndCopyFiles(\r
@@ -437,7 +471,6 @@ ProcessValidateAndCopyFiles(
     ShellStatus = SHELL_INVALID_PARAMETER;\r
     ShellCloseFileMetaArg(&List);\r
   } else if (List != NULL) {\r
-    ASSERT(List != NULL);\r
     ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink) != NULL);\r
     ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName != NULL);\r
     FileInfo    = NULL;\r