]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Refactor string manipulation
authorJaben Carsey <jaben.carsey@intel.com>
Fri, 22 Aug 2014 16:06:55 +0000 (16:06 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 22 Aug 2014 16:06:55 +0000 (16:06 +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: Erik Bjorge <erik.c.bjorge@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15882 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Vol.c

index c0d3c920f492fb70f332c59a26a14b2022c6b37f..aa5a20857fc41b334131b0521ade1d9065d5e42d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for attrib shell level 2 function.\r
 \r
-  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2014, 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
@@ -194,12 +194,11 @@ ShellCommandRunCd (
           //\r
           // change directory with a drive letter\r
           //\r
-          Drive = AllocateZeroPool(StrSize(Param1Copy));\r
+          Drive = AllocateCopyPool(StrSize(Param1Copy), Param1Copy);\r
           if (Drive == NULL) {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);\r
             ShellStatus = SHELL_OUT_OF_RESOURCES;\r
           } else {\r
-            Drive = StrCpy(Drive, Param1Copy);\r
             Path = StrStr(Drive, L":");\r
             ASSERT(Path != NULL);\r
             if (EFI_ERROR(ShellIsDirectory(Param1Copy))) {\r
index 9300d5ec35a1f46cec9594b90ac5e7d92705d185..4b6d2ea8e387ca3fb89f712c5f5cf55094e151ea 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for vol shell level 2 function.\r
 \r
-  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 2014, 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
@@ -101,7 +101,7 @@ HandleVol(
   ASSERT(SysInfo != NULL);\r
 \r
   if (Delete) {\r
-    StrCpy ((CHAR16 *) SysInfo->VolumeLabel, L"");\r
+    *((CHAR16 *) SysInfo->VolumeLabel) = CHAR_NULL;\r
     SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize(SysInfo->VolumeLabel);\r
     Status = EfiFpHandle->SetInfo(\r
       EfiFpHandle,\r
@@ -119,7 +119,7 @@ HandleVol(
       } \r
     }\r
     if (SysInfo != NULL) {\r
-      StrCpy ((CHAR16 *) SysInfo->VolumeLabel, Name);\r
+      StrnCpy ((CHAR16 *) SysInfo->VolumeLabel, Name, (Size1 > Size2?Size1/sizeof(CHAR16):Size2/sizeof(CHAR16))-1);\r
       SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + Size1;\r
       Status = EfiFpHandle->SetInfo(\r
         EfiFpHandle,\r