]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Refactor string manipulation in cp command
authorJaben Carsey <jaben.carsey@intel.com>
Thu, 7 Aug 2014 20:02:40 +0000 (20:02 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 7 Aug 2014 20:02:40 +0000 (20:02 +0000)
This patch replaces StrCpy with StrnCpy or refactors out the usage of StrCpy through some other means.
This patch replaces StrCat with StrnCat or refactors out the usage of StrCat through some other means.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15771 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c

index 5afbcb7761c5c7dff5181dc6ffbafebebc347664..3a0068393929e2d48ab1e6b0aad85b6dd3d666b0 100644 (file)
@@ -297,7 +297,7 @@ ValidateAndCopyFiles(
   SHELL_STATUS              ShellStatus;\r
   CHAR16                    *DestPath;\r
   VOID                      *Response;\r
   SHELL_STATUS              ShellStatus;\r
   CHAR16                    *DestPath;\r
   VOID                      *Response;\r
-  UINTN                     PathLen;\r
+  UINTN                     PathSize;\r
   CONST CHAR16              *Cwd;\r
   UINTN                     NewSize;\r
 \r
   CONST CHAR16              *Cwd;\r
   UINTN                     NewSize;\r
 \r
@@ -309,7 +309,7 @@ ValidateAndCopyFiles(
 \r
   DestPath    = NULL;\r
   ShellStatus = SHELL_SUCCESS;\r
 \r
   DestPath    = NULL;\r
   ShellStatus = SHELL_SUCCESS;\r
-  PathLen     = 0;\r
+  PathSize    = 0;\r
   Cwd         = ShellGetCurrentDir(NULL);\r
 \r
   ASSERT(FileList != NULL);\r
   Cwd         = ShellGetCurrentDir(NULL);\r
 \r
   ASSERT(FileList != NULL);\r
@@ -339,8 +339,8 @@ ValidateAndCopyFiles(
     NewSize =  StrSize(DestDir);\r
     NewSize += StrSize(Node->FullName);\r
     NewSize += (Cwd == NULL)? 0 : StrSize(Cwd);\r
     NewSize =  StrSize(DestDir);\r
     NewSize += StrSize(Node->FullName);\r
     NewSize += (Cwd == NULL)? 0 : StrSize(Cwd);\r
-    if (NewSize > PathLen) {\r
-      PathLen = NewSize;\r
+    if (NewSize > PathSize) {\r
+      PathSize = NewSize;\r
     }\r
 \r
     //\r
     }\r
 \r
     //\r
@@ -365,7 +365,7 @@ ValidateAndCopyFiles(
 \r
   HiiOutput   = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_CP_OUTPUT), NULL);\r
   HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);\r
 \r
   HiiOutput   = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_CP_OUTPUT), NULL);\r
   HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);\r
-  DestPath    = AllocateZeroPool(PathLen);\r
+  DestPath    = AllocateZeroPool(PathSize);\r
 \r
   if (DestPath == NULL || HiiOutput == NULL || HiiResultOk == NULL) {\r
     SHELL_FREE_NON_NULL(DestPath);\r
 \r
   if (DestPath == NULL || HiiOutput == NULL || HiiResultOk == NULL) {\r
     SHELL_FREE_NON_NULL(DestPath);\r
@@ -402,19 +402,19 @@ ValidateAndCopyFiles(
         // simple copy of a single file\r
         //\r
         if (Cwd != NULL) {\r
         // simple copy of a single file\r
         //\r
         if (Cwd != NULL) {\r
-          StrCpy(DestPath, Cwd);\r
+          StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16)-1);\r
         } else {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
           return (SHELL_INVALID_PARAMETER);\r
         }\r
         if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
         } else {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
           return (SHELL_INVALID_PARAMETER);\r
         }\r
         if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
-          StrCat(DestPath, L"\\");\r
+          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
         } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
         }\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
+        StrnCat(DestPath, DestDir, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
       } else {\r
       } else {\r
-        StrCpy(DestPath, DestDir);\r
+        StrnCpy(DestPath, DestDir, PathSize/sizeof(CHAR16) -1);\r
       }\r
     } else {\r
       //\r
       }\r
     } else {\r
       //\r
@@ -429,42 +429,42 @@ ValidateAndCopyFiles(
          // Copy to the root of CWD\r
          //\r
         if (Cwd != NULL) {\r
          // Copy to the root of CWD\r
          //\r
         if (Cwd != NULL) {\r
-          StrCpy(DestPath, Cwd);\r
+          StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);\r
         } else {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
           return (SHELL_INVALID_PARAMETER);\r
         }\r
         while (PathRemoveLastItem(DestPath));\r
         } else {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
           return (SHELL_INVALID_PARAMETER);\r
         }\r
         while (PathRemoveLastItem(DestPath));\r
-        StrCat(DestPath, DestDir+1);\r
-        StrCat(DestPath, Node->FileName);\r
+        StrnCat(DestPath, DestDir+1, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+        StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
       } else if (StrStr(DestDir, L":") == NULL) {\r
         if (Cwd != NULL) {\r
       } else if (StrStr(DestDir, L":") == NULL) {\r
         if (Cwd != NULL) {\r
-          StrCpy(DestPath, Cwd);\r
+          StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);\r
         } else {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
           return (SHELL_INVALID_PARAMETER);\r
         }\r
         if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
         } else {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
           return (SHELL_INVALID_PARAMETER);\r
         }\r
         if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
-          StrCat(DestPath, L"\\");\r
+          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
         } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
         }\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
+        StrnCat(DestPath, DestDir, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
         if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
         if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
-          StrCat(DestPath, L"\\");\r
+          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
         } else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
         }\r
         } else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
         }\r
-        StrCat(DestPath, Node->FileName);\r
+        StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
 \r
       } else {\r
 \r
       } else {\r
-        StrCpy(DestPath, DestDir);\r
+        StrnCpy(DestPath, DestDir, PathSize/sizeof(CHAR16) -1);\r
         if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
         if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
-          StrCat(DestPath, L"\\");\r
+          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
         } else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
           ((CHAR16*)DestDir)[StrLen(DestDir)-1] = CHAR_NULL;\r
         }\r
         } else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
           ((CHAR16*)DestDir)[StrLen(DestDir)-1] = CHAR_NULL;\r
         }\r
-        StrCat(DestPath, Node->FileName);\r
+        StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
       }\r
     }\r
 \r
       }\r
     }\r
 \r