]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
ShellPkg: Use safe string functions to refine code.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Cp.c
index 8faa54beee767fd8944df5b4036dffea890ec109..deff42e0494e0b0d889e5e744315e37ce19c7973 100644 (file)
@@ -2,7 +2,7 @@
   Main file for cp shell level 2 function.\r
 \r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2015, 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
@@ -427,20 +427,20 @@ ValidateAndCopyFiles(
         // simple copy of a single file\r
         //\r
         if (Cwd != NULL) {\r
-          StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16)-1);\r
+          StrCpyS(DestPath, PathSize / sizeof(CHAR16), Cwd);\r
         } else {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);  \r
           FreePool (CleanFilePathStr);\r
           return (SHELL_INVALID_PARAMETER);\r
         }\r
         if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {\r
-          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+          StrCatS(DestPath, PathSize / sizeof(CHAR16), L"\\");\r
         } else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {\r
           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
         }\r
-        StrnCat(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+        StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);\r
       } else {\r
-        StrnCpy(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) -1);\r
+        StrCpyS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);\r
       }\r
     } else {\r
       //\r
@@ -455,44 +455,44 @@ ValidateAndCopyFiles(
          // Copy to the root of CWD\r
          //\r
         if (Cwd != NULL) {\r
-          StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);\r
+          StrCpyS(DestPath, PathSize/sizeof(CHAR16), Cwd);\r
         } else {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp",  CleanFilePathStr); \r
           FreePool(CleanFilePathStr);\r
           return (SHELL_INVALID_PARAMETER);\r
         }\r
         while (PathRemoveLastItem(DestPath));\r
-        StrnCat(DestPath, CleanFilePathStr+1, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
-        StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+        StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr+1);\r
+        StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);\r
       } else if (StrStr(CleanFilePathStr, L":") == NULL) {\r
         if (Cwd != NULL) {\r
-          StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);\r
+          StrCpyS(DestPath, PathSize/sizeof(CHAR16), Cwd);\r
         } else {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);  \r
           FreePool(CleanFilePathStr);\r
           return (SHELL_INVALID_PARAMETER);\r
         }\r
         if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {\r
-          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+          StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");\r
         } else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {\r
           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
         }\r
-        StrnCat(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+        StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);\r
         if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
-          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+          StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");\r
         } else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
         }\r
-        StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+        StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);\r
 \r
       } else {\r
-        StrnCpy(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) -1);\r
+        StrCpyS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);\r
         if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
-          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+          StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");\r
         } else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
           ((CHAR16*)CleanFilePathStr)[StrLen(CleanFilePathStr)-1] = CHAR_NULL;\r
         }\r
-        StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+        StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);\r
       }\r
     }\r
     \r