This patch replaces StrCpy with StrnCpy or refactors out the usage of StrCpy through...
authorJaben Carsey <jaben.carsey@intel.com>
Fri, 29 Aug 2014 21:17:27 +0000 (21:17 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 29 Aug 2014 21:17:27 +0000 (21:17 +0000)
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: Erik Bjorge <erik.c.bjorge@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16002 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c

index 5329be4..ec204c3 100644 (file)
@@ -228,13 +228,12 @@ MappingListHasType(
   // specific has priority\r
   //\r
   if (Specific != NULL) {\r
-    NewSpecific = AllocateZeroPool(StrSize(Specific) + sizeof(CHAR16));\r
+    NewSpecific = AllocateCopyPool(StrSize(Specific) + sizeof(CHAR16), Specific);\r
     if (NewSpecific == NULL){\r
       return FALSE;\r
     }\r
-    StrCpy(NewSpecific, Specific);\r
     if (NewSpecific[StrLen(NewSpecific)-1] != L':') {\r
-      StrCat(NewSpecific, L":");\r
+      StrnCat(NewSpecific, L":", 2);\r
     }\r
 \r
     if (SearchList(MapList, NewSpecific, NULL, TRUE, FALSE, L";")) {\r
@@ -877,13 +876,12 @@ AddMappingFromMapping(
   EFI_STATUS                      Status;\r
   CHAR16                          *NewSName;\r
   \r
-  NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));\r
+  NewSName = AllocateCopyPool(StrSize(SName) + sizeof(CHAR16), SName);\r
   if (NewSName == NULL) {\r
     return (SHELL_OUT_OF_RESOURCES);\r
   }\r
-  StrCpy(NewSName, SName);\r
   if (NewSName[StrLen(NewSName)-1] != L':') {\r
-    StrCat(NewSName, L":");\r
+    StrnCat(NewSName, L":", 2);\r
   }\r
 \r
   if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {\r
@@ -930,13 +928,12 @@ AddMappingFromHandle(
   EFI_STATUS                Status;\r
   CHAR16                    *NewSName;\r
   \r
-  NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));\r
+  NewSName = AllocateCopyPool(StrSize(SName) + sizeof(CHAR16), SName);\r
   if (NewSName == NULL) {\r
     return (SHELL_OUT_OF_RESOURCES);\r
   }\r
-  StrCpy(NewSName, SName);\r
   if (NewSName[StrLen(NewSName)-1] != L':') {\r
-    StrCat(NewSName, L":");\r
+    StrnCat(NewSName, L":", 2);\r
   }\r
 \r
   if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {\r
index a661b45..6cc5dcf 100644 (file)
@@ -77,6 +77,7 @@ CascadeDelete(
   EFI_STATUS            Status;\r
   SHELL_PROMPT_RESPONSE *Resp;\r
   CHAR16                *TempName;\r
+  UINTN                 NewSize;\r
 \r
   Resp                  = NULL;\r
   ShellStatus           = SHELL_SUCCESS;\r
@@ -125,13 +126,14 @@ CascadeDelete(
           //\r
           // Update the node filename to have full path with file system identifier\r
           //\r
-          TempName = AllocateZeroPool(StrSize(Node->FullName) + StrSize(Node2->FullName));\r
+          NewSize = StrSize(Node->FullName) + StrSize(Node2->FullName);\r
+          TempName = AllocateZeroPool(NewSize);\r
           if (TempName == NULL) {\r
             ShellStatus = SHELL_OUT_OF_RESOURCES;\r
           } else {\r
-            StrCpy(TempName, Node->FullName);\r
+            StrnCpy(TempName, Node->FullName, NewSize/sizeof(CHAR16) -1);\r
             TempName[StrStr(TempName, L":")+1-TempName] = CHAR_NULL;\r
-            StrCat(TempName, Node2->FullName);\r
+            StrnCat(TempName, Node2->FullName, NewSize/sizeof(CHAR16) -1 - StrLen(TempName));\r
             FreePool((VOID*)Node2->FullName);\r
             Node2->FullName = TempName;\r
 \r