]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
ShellPkg: Use safe string functions to refine code.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Mv.c
index c025cebe5689a6303c6fa3f37e99ef3ac43e2534..40ba00b4934c31da8881b3936bdac46d24ceded7 100644 (file)
@@ -2,7 +2,7 @@
   Main file for mv shell level 2 function.\r
 \r
   (C) Copyright 2013-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
@@ -187,7 +187,7 @@ GetDestinationLocation(
     if (DestPath == NULL) {\r
       return (SHELL_OUT_OF_RESOURCES);\r
     }\r
-    StrCpy(DestPath, Cwd);\r
+    StrCpyS(DestPath, StrSize(Cwd) / sizeof(CHAR16), Cwd);\r
     while (PathRemoveLastItem(DestPath)) ;\r
 \r
     //\r
@@ -220,13 +220,13 @@ GetDestinationLocation(
         ShellCloseFileMetaArg(&DestList);\r
         return (SHELL_OUT_OF_RESOURCES);\r
       }\r
-      StrCpy(DestPath, Cwd);\r
+      StrCpyS(DestPath, NewSize / sizeof(CHAR16), Cwd);\r
       if (DestPath[StrLen(DestPath)-1] != L'\\' && DestParameter[0] != L'\\') {\r
-        StrCat(DestPath, L"\\");\r
+        StrCatS(DestPath, NewSize / sizeof(CHAR16), L"\\");\r
       } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestParameter[0] == L'\\') {\r
         ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
       }\r
-      StrCat(DestPath, DestParameter);\r
+      StrCatS(DestPath, NewSize / sizeof(CHAR16), DestParameter);\r
     } else {\r
       ASSERT(DestPath == NULL);\r
       DestPath = StrnCatGrow(&DestPath, NULL, DestParameter, 0);\r
@@ -256,8 +256,8 @@ GetDestinationLocation(
         ShellCloseFileMetaArg(&DestList);\r
         return (SHELL_OUT_OF_RESOURCES);\r
       }\r
-      StrCpy(DestPath, Node->FullName);\r
-      StrCat(DestPath, L"\\");\r
+      StrCpyS(DestPath, (StrSize(Node->FullName)+sizeof(CHAR16)) / sizeof(CHAR16), Node->FullName);\r
+      StrCatS(DestPath, (StrSize(Node->FullName)+sizeof(CHAR16)) / sizeof(CHAR16), L"\\");\r
     } else {\r
       //\r
       // cant move multiple files onto a single file.\r
@@ -351,11 +351,11 @@ CreateFullDestPath(
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
-  StrnCpy(*FullDestPath, *DestPath, Size / sizeof(CHAR16) - 1);\r
+  StrCpyS(*FullDestPath, Size / sizeof(CHAR16), *DestPath);\r
   if ((*FullDestPath)[StrLen(*FullDestPath)-1] != L'\\' && FileName[0] != L'\\') {\r
-    StrnCat(*FullDestPath, L"\\",Size / sizeof(CHAR16) - 1 - StrLen(*FullDestPath));\r
+    StrCatS(*FullDestPath, Size / sizeof(CHAR16), L"\\");\r
   }\r
-  StrnCat(*FullDestPath, FileName, Size / sizeof(CHAR16) - 1 - StrLen(*FullDestPath));\r
+  StrCatS(*FullDestPath, Size / sizeof(CHAR16), FileName);\r
 \r
   return (EFI_SUCCESS);\r
 }\r
@@ -403,10 +403,10 @@ MoveWithinFileSystems(
   } else {\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
+      StrCpyS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), L"\\");\r
+      StrCatS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), DestPath);\r
     } else {\r
-      StrCpy(NewFileInfo->FileName, DestPath);\r
+      StrCpyS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), DestPath);\r
     }\r
     Length = StrLen(NewFileInfo->FileName);\r
     if (Length > 0) {\r
@@ -419,7 +419,7 @@ MoveWithinFileSystems(
         //\r
         NewFileInfo->FileName[Length] = CHAR_NULL;\r
       }\r
-      StrCat(NewFileInfo->FileName, Node->FileName);\r
+      StrCatS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), Node->FileName);\r
     }\r
     NewFileInfo->Size = SIZE_OF_EFI_FILE_INFO + StrSize(NewFileInfo->FileName);\r
 \r