]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Use safe string functions to refine code.
authorQiu Shumin <shumin.qiu@intel.com>
Tue, 30 Jun 2015 03:18:31 +0000 (03:18 +0000)
committershenshushi <shenshushi@Edk2>
Tue, 30 Jun 2015 03:18:31 +0000 (03:18 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17730 6f19259b-4bc3-4df7-8a09-765794883524

18 files changed:
ShellPkg/Application/Shell/FileHandleWrappers.c
ShellPkg/Application/Shell/Shell.c
ShellPkg/Application/Shell/ShellEnvVar.c
ShellPkg/Application/Shell/ShellManParser.c
ShellPkg/Application/Shell/ShellParametersProtocol.c
ShellPkg/Application/Shell/ShellProtocol.c
ShellPkg/Library/UefiDpLib/DpUtilities.c
ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c
ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c
ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c
ShellPkg/Library/UefiShellDriver1CommandsLib/Drivers.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Vol.c
ShellPkg/Library/UefiShellLib/UefiShellLib.c
ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c

index 984cd36957af6107b4209f231e8d521a696f5f4e..fc68b78d5752f1a94a5929a34ecea9d8685dc821 100644 (file)
@@ -2,7 +2,7 @@
   EFI_FILE_PROTOCOL wrappers for other items (Like Environment Variables,\r
   StdIn, StdOut, StdErr, etc...).\r
 \r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
   (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -509,19 +509,23 @@ FileInterfaceStdInRead(
         if (StrStr(CurrentString + TabPos, L":") == NULL) {\r
           Cwd = ShellInfoObject.NewEfiShellProtocol->GetCurDir(NULL);\r
           if (Cwd != NULL) {\r
-            StrnCpy(TabStr, Cwd, (*BufferSize)/sizeof(CHAR16) - 1);\r
+            StrCpyS(TabStr, (*BufferSize)/sizeof(CHAR16), Cwd);\r
             if (TabStr[StrLen(TabStr)-1] == L'\\' && *(CurrentString + TabPos) == L'\\' ) {\r
               TabStr[StrLen(TabStr)-1] = CHAR_NULL;\r
             }\r
-            StrnCat(TabStr, CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16));\r
+            StrnCatS( TabStr, \r
+                      (*BufferSize)/sizeof(CHAR16), \r
+                      CurrentString + TabPos, \r
+                      (StringLen - TabPos) * sizeof (CHAR16)\r
+                      );\r
           } else {\r
             *TabStr = CHAR_NULL;\r
-            StrnCat(TabStr, CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16));\r
+            StrnCatS(TabStr, (*BufferSize)/sizeof(CHAR16), CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16));\r
           }\r
         } else {\r
-          StrnCpy(TabStr, CurrentString + TabPos, (*BufferSize)/sizeof(CHAR16) - 1);\r
+          StrCpyS(TabStr, (*BufferSize)/sizeof(CHAR16), CurrentString + TabPos);\r
         }\r
-        StrnCat(TabStr, L"*", (*BufferSize)/sizeof(CHAR16) - 1 - StrLen(TabStr));\r
+        StrnCatS(TabStr, (*BufferSize)/sizeof(CHAR16), L"*", (*BufferSize)/sizeof(CHAR16) - 1 - StrLen(TabStr));\r
         FoundFileList = NULL;\r
         Status  = ShellInfoObject.NewEfiShellProtocol->FindFiles(TabStr, &FoundFileList);\r
         for ( TempStr = CurrentString\r
index 377e1ca7b7e57890bca91eea34826ad03094360b..779bb53df64f1d167f7cea3ab67ae48ae0ae6d84 100644 (file)
@@ -1079,10 +1079,10 @@ DoStartupScript(
     if (FileStringPath == NULL) {\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
-    StrnCpy(FileStringPath, ShellInfoObject.ShellInitSettings.FileName, NewSize/sizeof(CHAR16) -1);\r
+    StrCpyS(FileStringPath, NewSize/sizeof(CHAR16), ShellInfoObject.ShellInitSettings.FileName);\r
     if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r
-      StrnCat(FileStringPath, L" ", NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);\r
-      StrnCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);\r
+      StrnCatS(FileStringPath, NewSize/sizeof(CHAR16), L" ", NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);\r
+      StrnCatS(FileStringPath, NewSize/sizeof(CHAR16), ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);\r
     }\r
     Status = RunCommand(FileStringPath);\r
     FreePool(FileStringPath);\r
@@ -1488,11 +1488,20 @@ ShellConvertVariables (
     ;  MasterEnvList != NULL && *MasterEnvList != CHAR_NULL\r
     ;  MasterEnvList += StrLen(MasterEnvList) + 1\r
    ){\r
-    StrnCpy(ItemTemp, L"%", ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1);\r
-    StrnCat(ItemTemp, MasterEnvList, ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1 - StrLen(ItemTemp));\r
-    StrnCat(ItemTemp, L"%", ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1 - StrLen(ItemTemp));\r
+    StrCpyS( ItemTemp, \r
+              ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16)), \r
+              L"%"\r
+              );\r
+    StrCatS( ItemTemp, \r
+              ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16)), \r
+              MasterEnvList\r
+              );\r
+    StrCatS( ItemTemp, \r
+              ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16)), \r
+              L"%"\r
+              );\r
     ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, ItemTemp, EfiShellGetEnv(MasterEnvList), TRUE, FALSE);\r
-    StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);\r
+    StrCpyS(NewCommandLine1, NewSize/sizeof(CHAR16), NewCommandLine2);\r
   }\r
   if (CurrentScriptFile != NULL) {\r
     for (AliasListNode = (ALIAS_LIST*)GetFirstNode(&CurrentScriptFile->SubstList)\r
@@ -1500,7 +1509,7 @@ ShellConvertVariables (
       ;  AliasListNode = (ALIAS_LIST*)GetNextNode(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r
    ){\r
     ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);\r
-    StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);\r
+    StrCpyS(NewCommandLine1, NewSize/sizeof(CHAR16), NewCommandLine2);\r
     }\r
   }\r
 \r
@@ -1513,7 +1522,7 @@ ShellConvertVariables (
   // Now cleanup any straggler intentionally ignored "%" characters\r
   //\r
   ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, L"^%", L"%", TRUE, FALSE);\r
-  StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);\r
+  StrCpyS(NewCommandLine1, NewSize/sizeof(CHAR16), NewCommandLine2);\r
   \r
   FreePool(NewCommandLine2);\r
   FreePool(ItemTemp);\r
@@ -1991,6 +2000,7 @@ DoHelpUpdate(
   CHAR16 *Walker;\r
   CHAR16 *NewCommandLine;\r
   EFI_STATUS Status;\r
+  UINTN  NewCmdLineSize;\r
 \r
   Status = EFI_SUCCESS;\r
 \r
@@ -2005,7 +2015,8 @@ DoHelpUpdate(
       if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {\r
         CurrentParameter[0] = L' ';\r
         CurrentParameter[1] = L' ';\r
-        NewCommandLine = AllocateZeroPool(StrSize(L"help ") + StrSize(*CmdLine));\r
+        NewCmdLineSize = StrSize(L"help ") + StrSize(*CmdLine);\r
+        NewCommandLine = AllocateZeroPool(NewCmdLineSize);\r
         if (NewCommandLine == NULL) {\r
           Status = EFI_OUT_OF_RESOURCES;\r
           break;\r
@@ -2014,8 +2025,8 @@ DoHelpUpdate(
         //\r
         // We know the space is sufficient since we just calculated it.\r
         //\r
-        StrnCpy(NewCommandLine, L"help ", 5);\r
-        StrnCat(NewCommandLine, *CmdLine, StrLen(*CmdLine));\r
+        StrnCpyS(NewCommandLine, NewCmdLineSize/sizeof(CHAR16), L"help ", 5);\r
+        StrnCatS(NewCommandLine, NewCmdLineSize/sizeof(CHAR16), *CmdLine, StrLen(*CmdLine));\r
         SHELL_FREE_NON_NULL(*CmdLine);\r
         *CmdLine = NewCommandLine;\r
         break;\r
@@ -2658,7 +2669,10 @@ RunScriptFileHandle (
       ; // conditional increment in the body of the loop\r
   ){\r
     ASSERT(CommandLine2 != NULL);\r
-    StrnCpy(CommandLine2, NewScriptFile->CurrentCommand->Cl, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);\r
+    StrCpyS( CommandLine2, \r
+              PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16), \r
+              NewScriptFile->CurrentCommand->Cl\r
+              );\r
 \r
     //\r
     // NULL out comments\r
@@ -2679,7 +2693,10 @@ RunScriptFileHandle (
       //\r
       // Due to variability in starting the find and replace action we need to have both buffers the same.\r
       //\r
-      StrnCpy(CommandLine, CommandLine2, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);\r
+      StrCpyS( CommandLine, \r
+                PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16), \r
+                CommandLine2\r
+                );\r
 \r
       //\r
       // Remove the %0 to %9 from the command line (if we have some arguments)\r
@@ -2731,7 +2748,10 @@ RunScriptFileHandle (
       Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%8", L"\"\"", FALSE, FALSE);\r
       Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%9", L"\"\"", FALSE, FALSE);\r
 \r
-      StrnCpy(CommandLine2, CommandLine, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);\r
+      StrCpyS( CommandLine2, \r
+                PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16), \r
+                CommandLine\r
+                );\r
 \r
       LastCommand = NewScriptFile->CurrentCommand;\r
 \r
index de09174c624d6b0c736993ca4f3e48d7ca55cefc..8ed14b34a2f48992c0ae3a2b29c53f54d18615af 100644 (file)
@@ -339,7 +339,10 @@ SetEnvironmentVariables(
     //\r
     // Copy the string into the Key, leaving the last character allocated as NULL to terminate\r
     //\r
-    StrnCpy(Node->Key, CurrentString, StrStr(CurrentString, L"=") - CurrentString);\r
+    StrCpyS( Node->Key, \r
+              StrStr(CurrentString, L"=") - CurrentString + 1, \r
+              CurrentString\r
+              );\r
 \r
     //\r
     // ValueSize = TotalSize - already removed size - size for '=' + size for terminator (the last 2 items cancel each other)\r
index 30470e1987e3c49a79832961a70c7b6bb5d93397..78b8decd832412584732dea1459dffacb010e46a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to shell MAN file parser.\r
 \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
@@ -43,8 +43,16 @@ GetManFileName(
   } else {\r
     Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16));\r
     if (Buffer != NULL) {\r
-      StrnCpy(Buffer, ManFileName, StrLen(ManFileName));\r
-      StrnCat(Buffer, L".man", 4);\r
+      StrnCpyS( Buffer, \r
+                (StrSize(ManFileName) + 4*sizeof(CHAR16))/sizeof(CHAR16), \r
+                ManFileName, \r
+                StrLen(ManFileName)\r
+                );\r
+      StrnCatS( Buffer, \r
+                (StrSize(ManFileName) + 4*sizeof(CHAR16))/sizeof(CHAR16),\r
+                L".man", \r
+                4\r
+                );\r
     }\r
   }\r
   return (Buffer);\r
@@ -392,9 +400,9 @@ ManBufferFindTitleSection(
   if (TitleString == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
-  StrnCpy(TitleString, StartString, TitleLength/sizeof(CHAR16) - 1);\r
-  StrnCat(TitleString, Command,     TitleLength/sizeof(CHAR16) - 1 - StrLen(TitleString));\r
-  StrnCat(TitleString, EndString,   TitleLength/sizeof(CHAR16) - 1 - StrLen(TitleString));\r
+  StrCpyS(TitleString, TitleLength/sizeof(CHAR16), StartString);\r
+  StrCatS(TitleString, TitleLength/sizeof(CHAR16), Command);\r
+  StrCatS(TitleString, TitleLength/sizeof(CHAR16), EndString);\r
 \r
   CurrentLocation = StrStr(*Buffer, TitleString);\r
   if (CurrentLocation == NULL){\r
@@ -418,7 +426,7 @@ ManBufferFindTitleSection(
         if (*BriefDesc == NULL) {\r
           Status = EFI_OUT_OF_RESOURCES;\r
         } else {\r
-          StrnCpy(*BriefDesc, CurrentLocation, TitleEnd-CurrentLocation);\r
+          StrnCpyS(*BriefDesc, (*BriefSize)/sizeof(CHAR16), CurrentLocation, TitleEnd-CurrentLocation);\r
         }\r
       }\r
 \r
@@ -495,8 +503,8 @@ ManFileFindTitleSection(
     FreePool(ReadLine);\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
-  StrnCpy(TitleString, L".TH ", TitleSize/sizeof(CHAR16) - 1);\r
-  StrnCat(TitleString, Command, TitleSize/sizeof(CHAR16) - 1 - StrLen(TitleString));\r
+  StrCpyS(TitleString, TitleSize/sizeof(CHAR16), L".TH ");\r
+  StrCatS(TitleString, TitleSize/sizeof(CHAR16), Command);\r
 \r
   TitleLen = StrLen(TitleString);\r
   for (;!ShellFileHandleEof(Handle);Size = 1024) {\r
@@ -532,7 +540,7 @@ ManFileFindTitleSection(
           Status = EFI_OUT_OF_RESOURCES;\r
           break;\r
         }\r
-        StrnCpy(*BriefDesc, TitleEnd, (*BriefSize)/sizeof(CHAR16) - 1);\r
+        StrCpyS(*BriefDesc, (*BriefSize)/sizeof(CHAR16), TitleEnd);\r
       }\r
       break;\r
     }\r
index 00b413e90b4d136f64125c3bce9cb1489a0256d3..de29c25ae8352ec89a6bdbffa57b0b339614376f 100644 (file)
@@ -125,7 +125,7 @@ DEBUG_CODE_END();
     return (EFI_NOT_FOUND);\r
   }\r
 \r
-  StrnCpy(*TempParameter, (*Walker), NextDelim - *Walker);\r
+  StrnCpyS(*TempParameter, Length, (*Walker), NextDelim - *Walker);\r
 \r
   //\r
   // Add a CHAR_NULL if we didnt get one via the copy\r
@@ -1012,7 +1012,7 @@ UpdateStdInStdOutStdErr(
   //\r
   // re-populate the string to support any filenames that were in quotes.\r
   //\r
-  StrnCpy(CommandLineCopy, NewCommandLine, StrLen(NewCommandLine));\r
+  StrnCpyS(CommandLineCopy, StrSize(CommandLineCopy)/sizeof(CHAR16), NewCommandLine, StrLen(NewCommandLine));\r
 \r
   if (FirstLocation != CommandLineCopy + StrLen(CommandLineCopy)\r
     && ((UINTN)(FirstLocation - CommandLineCopy) < StrLen(NewCommandLine))\r
index 72d42d7222810641b32d0a43e58c40590c1d475a..249e1e19d80264ef4ebe4e8f6fbab99534fb71a8 100644 (file)
@@ -537,12 +537,12 @@ EfiShellGetDevicePathFromFilePath(
     if (NewPath == NULL) {\r
       return (NULL);\r
     }\r
-    StrnCpy(NewPath, Cwd, Size/sizeof(CHAR16)-1);\r
+    StrCpyS(NewPath, Size/sizeof(CHAR16), Cwd);\r
     if (*Path == L'\\') {\r
       Path++;\r
       while (PathRemoveLastItem(NewPath)) ;\r
     }\r
-    StrnCat(NewPath, Path, Size/sizeof(CHAR16) - 1 - StrLen(NewPath));\r
+    StrCatS(NewPath, Size/sizeof(CHAR16), Path);\r
     DevicePathForReturn = EfiShellGetDevicePathFromFilePath(NewPath);\r
     FreePool(NewPath);\r
     return (DevicePathForReturn);\r
@@ -2220,7 +2220,7 @@ ShellSearchHandle(
 \r
   CurrentFilePattern = AllocateZeroPool((NextFilePatternStart-FilePattern+1)*sizeof(CHAR16));\r
   ASSERT(CurrentFilePattern != NULL);\r
-  StrnCpy(CurrentFilePattern, FilePattern, NextFilePatternStart-FilePattern);\r
+  StrCpyS(CurrentFilePattern, NextFilePatternStart-FilePattern+1, FilePattern);\r
 \r
   if (CurrentFilePattern[0]   == CHAR_NULL\r
     &&NextFilePatternStart[0] == CHAR_NULL\r
@@ -2284,8 +2284,8 @@ ShellSearchHandle(
             if (NewFullName == NULL) {\r
               Status = EFI_OUT_OF_RESOURCES;\r
             } else {\r
-              StrnCpy(NewFullName, MapName, Size/sizeof(CHAR16)-1);\r
-              StrnCat(NewFullName, ShellInfoNode->FullName+1, (Size/sizeof(CHAR16))-StrLen(NewFullName)-1);\r
+              StrCpyS(NewFullName, Size/sizeof(CHAR16), MapName);\r
+              StrCatS(NewFullName, Size/sizeof(CHAR16), ShellInfoNode->FullName+1);\r
               FreePool((VOID*)ShellInfoNode->FullName);\r
               ShellInfoNode->FullName = NewFullName;\r
             }\r
@@ -2615,7 +2615,10 @@ EfiShellGetEnvEx(
       ; Node = (ENV_VAR_LIST*)GetNextNode(&List, &Node->Link)\r
      ){\r
       ASSERT(Node->Key != NULL);\r
-      StrnCpy(CurrentWriteLocation, Node->Key,  (Size)/sizeof(CHAR16) - (CurrentWriteLocation - ((CHAR16*)Buffer)) - 1);\r
+      StrCpyS( CurrentWriteLocation, \r
+                (Size)/sizeof(CHAR16) - (CurrentWriteLocation - ((CHAR16*)Buffer)), \r
+                Node->Key\r
+                );\r
       CurrentWriteLocation += StrLen(CurrentWriteLocation) + 1;\r
     }\r
 \r
@@ -3046,7 +3049,11 @@ EfiShellGetHelpText(
       FixCommand = AllocateZeroPool(StrSize(Command) - 4 * sizeof (CHAR16));\r
       ASSERT(FixCommand != NULL);\r
 \r
-      StrnCpy(FixCommand, Command, StrLen(Command)-4);\r
+      StrnCpyS( FixCommand, \r
+                (StrSize(Command) - 4 * sizeof (CHAR16))/sizeof(CHAR16), \r
+                Command, \r
+                StrLen(Command)-4\r
+                );\r
       Status = ProcessManFile(FixCommand, FixCommand, Sections, NULL, HelpText);\r
       FreePool(FixCommand);\r
       return Status;\r
index ef204ffef156eb2ac0abe437a950459ebe95e3e9..7290285e23da6ae143273ef1cfb4bc57e0f6fe92 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Utility functions used by the Dp application.\r
 \r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.\r
+  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.\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
@@ -141,10 +141,10 @@ GetShortPdbFileName (
   UINTN StartIndex;\r
   UINTN EndIndex;\r
 \r
-  ZeroMem (UnicodeBuffer, DXE_PERFORMANCE_STRING_LENGTH * sizeof (CHAR16));\r
+  ZeroMem (UnicodeBuffer, (DP_GAUGE_STRING_LENGTH + 1) * sizeof (CHAR16));\r
 \r
   if (PdbFileName == NULL) {\r
-    StrnCpy (UnicodeBuffer, L" ", 1);\r
+    StrnCpyS (UnicodeBuffer, DP_GAUGE_STRING_LENGTH + 1, L" ", 1);\r
   } else {\r
     StartIndex = 0;\r
     for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++)\r
@@ -261,7 +261,7 @@ GetNameFromHandle (
                                );\r
     if (!EFI_ERROR (Status)) {\r
       SHELL_FREE_NON_NULL (PlatformLanguage);\r
-      StrnCpy (mGaugeString, StringPtr, DP_GAUGE_STRING_LENGTH);\r
+      StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr);\r
       mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
       return;\r
     }\r
@@ -305,7 +305,7 @@ GetNameFromHandle (
         //\r
         // Method 3. Get the name string from FFS UI section\r
         //\r
-        StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH);\r
+        StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, NameString);\r
         mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
         FreePool (NameString);\r
       } else {\r
@@ -321,7 +321,7 @@ GetNameFromHandle (
       //\r
       NameString = ConvertDevicePathToText (LoadedImageDevicePath, TRUE, FALSE);\r
       if (NameString != NULL) {\r
-        StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH);\r
+        StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, NameString);\r
         mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
         FreePool (NameString);\r
         return;\r
@@ -334,7 +334,7 @@ GetNameFromHandle (
   //\r
   StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL);\r
   ASSERT (StringPtr != NULL);\r
-  StrnCpy (mGaugeString, StringPtr, DP_GAUGE_STRING_LENGTH);\r
+  StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr);\r
   FreePool (StringPtr);\r
 }\r
 \r
index 368d6a487b87cee5618c25012a81c68da959f488..9bd7b2cedd25728276a031226b0d3165300c1cf0 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for support of shell consist mapping.\r
 \r
-  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 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
@@ -116,7 +116,7 @@ CatPrint (
     ASSERT (Str->Str != NULL);\r
   }\r
 \r
-  StrnCat (Str->Str, AppendStr, StringSize/sizeof(CHAR16) - 1 - StrLen(Str->Str));\r
+  StrCatS (Str->Str, StringSize/sizeof(CHAR16), AppendStr);\r
   Str->Len = StringSize;\r
 \r
   FreePool (AppendStr);\r
index 3ae61c9c3fdcdd4aefde8262eebcda9f7cc583c2..d818b9b8d4707d9814dc677c5eef9adf5135bd44 100644 (file)
@@ -2,7 +2,7 @@
   Main file for DmpStore shell Debug1 function.\r
    \r
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 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
@@ -406,7 +406,7 @@ CascadeProcessVariables (
     FoundVarName = AllocateZeroPool (NameSize);\r
     if (FoundVarName != NULL) {\r
       if (PrevName != NULL) {\r
-        StrnCpy(FoundVarName, PrevName, NameSize/sizeof(CHAR16)-1);\r
+        StrCpyS(FoundVarName, NameSize/sizeof(CHAR16), PrevName);\r
       }\r
 \r
       Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);\r
index ed23365363cb5191e5e37394af6da42b76cc2fc4..acd8512ff3e876e4318c4f50c5ff79092932e577 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implements filebuffer interface functions.\r
 \r
-  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2005 - 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
@@ -507,7 +507,7 @@ FileBufferPrintLine (
   PrintLine = AllocatePool (BufLen);\r
   ASSERT (PrintLine != NULL);\r
 \r
-  StrnCpy (PrintLine, Buffer, MIN(Limit, MainEditor.ScreenSize.Column));\r
+  StrnCpyS (PrintLine, BufLen/sizeof(CHAR16), Buffer, MIN(Limit, MainEditor.ScreenSize.Column));\r
   for (; Limit < MainEditor.ScreenSize.Column; Limit++) {\r
     PrintLine[Limit] = L' ';\r
   }\r
index b91ae360caac8151f607216d23bbbe2ab6ab3e77..dd878c4cb7fc2b4677001861464ea00e9d63f34c 100644 (file)
@@ -3229,13 +3229,13 @@ QueryTable (
     //\r
     if ((High > Low && Key >= Low && Key <= High) \r
       || (Table[Index].Key == Key)) {\r
-      StrnCpy (Info, Table[Index].Info, InfoLen-1);\r
-      StrnCat (Info, L"\n", InfoLen - 1 - StrLen(Info));\r
+      StrCpyS (Info, InfoLen, Table[Index].Info);\r
+      StrCatS (Info, InfoLen, L"\n");\r
       return Key;\r
     }\r
   }\r
 \r
-  StrnCpy (Info, L"Undefined Value\n", InfoLen - 1);\r
+  StrCpyS (Info, InfoLen, L"Undefined Value\n");\r
   return QUERY_TABLE_UNFOUND;\r
 }\r
 \r
index f1c2a7f7bf5d2f2d1462284555715b2ec91de7a9..06bd3515199b2d9a4cee0b034ba846305fc0a5ad 100644 (file)
@@ -2,7 +2,7 @@
   Main file for Drivers shell Driver1 function.\r
 \r
   (C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 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
@@ -282,7 +282,7 @@ ShellCommandRunDrivers (
         TruncatedDriverName = NULL;\r
         if (!SfoFlag && (FullDriverName != NULL)) {\r
           TruncatedDriverName = AllocateZeroPool ((MAX_LEN_DRIVER_NAME + 1) * sizeof (CHAR16));\r
-          StrnCpy (TruncatedDriverName, FullDriverName, MAX_LEN_DRIVER_NAME);\r
+          StrCpyS (TruncatedDriverName, MAX_LEN_DRIVER_NAME + 1, FullDriverName);\r
         }\r
 \r
         ShellPrintEx(\r
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
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
index e4176adfe0a122be5becd6556a30a3ff9a5cee79..a53a88c2377008af1b072fcab992d31bc78b11bc 100644 (file)
@@ -2,7 +2,7 @@
   Main file for attrib 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
@@ -132,9 +132,9 @@ CascadeDelete(
           if (TempName == NULL) {\r
             ShellStatus = SHELL_OUT_OF_RESOURCES;\r
           } else {\r
-            StrnCpy(TempName, Node->FullName, NewSize/sizeof(CHAR16) -1);\r
+            StrCpyS(TempName, NewSize/sizeof(CHAR16), Node->FullName);\r
             TempName[StrStr(TempName, L":")+1-TempName] = CHAR_NULL;\r
-            StrnCat(TempName, Node2->FullName, NewSize/sizeof(CHAR16) -1 - StrLen(TempName));\r
+            StrCatS(TempName, NewSize/sizeof(CHAR16), Node2->FullName);\r
             FreePool((VOID*)Node2->FullName);\r
             Node2->FullName = TempName;\r
 \r
index 39b8ad9ec8c86eaa0fc9de1e36b0e45789dba909..a6f0296d760363a511f4d35261ed2c9a9c9e81ac 100644 (file)
@@ -2,7 +2,7 @@
   Main file for vol shell level 2 function.\r
 \r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 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
@@ -120,7 +120,10 @@ HandleVol(
       } \r
     }\r
     if (SysInfo != NULL) {\r
-      StrnCpy ((CHAR16 *) SysInfo->VolumeLabel, Name, (Size1 > Size2?Size1/sizeof(CHAR16):Size2/sizeof(CHAR16))-1);\r
+      StrCpyS ( (CHAR16 *) SysInfo->VolumeLabel, \r
+                  (Size1>Size2? Size1/sizeof(CHAR16) : Size2/sizeof(CHAR16)), \r
+                  Name\r
+                  );\r
       SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + Size1;\r
       Status = EfiFpHandle->SetInfo(\r
         EfiFpHandle,\r
index f82668b60fe0bc3f8a3869168cba9ad814c0408d..5b4c6d3fb7e392468aa1a79b79c193779d865d48 100644 (file)
@@ -1713,8 +1713,8 @@ ShellFindFilePath (
     if (TestPath == NULL) {\r
       return (NULL);\r
     }\r
-    StrnCpy(TestPath, Path, Size/sizeof(CHAR16) - 1);\r
-    StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));\r
+    StrCpyS(TestPath, Size/sizeof(CHAR16), Path);\r
+    StrCatS(TestPath, Size/sizeof(CHAR16), FileName);\r
     Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
     if (!EFI_ERROR(Status)){\r
       if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r
@@ -1746,12 +1746,12 @@ ShellFindFilePath (
           *TempChar = CHAR_NULL;\r
         }\r
         if (TestPath[StrLen(TestPath)-1] != L'\\') {\r
-          StrnCat(TestPath, L"\\", Size/sizeof(CHAR16) - 1 - StrLen(TestPath));\r
+          StrCatS(TestPath, Size/sizeof(CHAR16), L"\\");\r
         }\r
         if (FileName[0] == L'\\') {\r
           FileName++;\r
         }\r
-        StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));\r
+        StrCatS(TestPath, Size/sizeof(CHAR16), FileName);\r
         if (StrStr(Walker, L";") != NULL) {\r
           Walker = StrStr(Walker, L";") + 1;\r
         } else {\r
@@ -1820,9 +1820,9 @@ ShellFindFilePathEx (
     return (NULL);\r
   }\r
   for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension;  TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1){\r
-    StrnCpy(TestPath, FileName, Size/sizeof(CHAR16) - 1);\r
+    StrCpyS(TestPath, Size/sizeof(CHAR16), FileName);\r
     if (ExtensionWalker != NULL) {\r
-      StrnCat(TestPath, ExtensionWalker, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));\r
+      StrCatS(TestPath, Size/sizeof(CHAR16), ExtensionWalker);\r
     }\r
     TempChar = StrStr(TestPath, L";");\r
     if (TempChar != NULL) {\r
@@ -2109,10 +2109,19 @@ InternalCommandLineParse (
       CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value);\r
       ASSERT(CurrentItemPackage->Value != NULL);\r
       if (ValueSize == 0) {\r
-        StrnCpy(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1);\r
+        StrCpyS( CurrentItemPackage->Value, \r
+                  CurrentValueSize/sizeof(CHAR16), \r
+                  Argv[LoopCounter]\r
+                  );\r
       } else {\r
-        StrnCat(CurrentItemPackage->Value, L" ", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));\r
-        StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));\r
+        StrCatS( CurrentItemPackage->Value, \r
+                  CurrentValueSize/sizeof(CHAR16), \r
+                  L" "\r
+                  );\r
+        StrCatS( CurrentItemPackage->Value, \r
+                  CurrentValueSize/sizeof(CHAR16), \r
+                  Argv[LoopCounter]\r
+                  );\r
       }\r
       ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r
       \r
@@ -2635,14 +2644,14 @@ ShellCopySearchAndReplace(
         FreePool(Replace);\r
         return (EFI_BUFFER_TOO_SMALL);\r
       }\r
-      StrnCat(NewString, Replace, NewSize/sizeof(CHAR16) - 1 - StrLen(NewString));\r
+      StrCatS(NewString, NewSize/sizeof(CHAR16), Replace);\r
     } else {\r
       Size = StrSize(NewString);\r
       if (Size + sizeof(CHAR16) > NewSize) {\r
         FreePool(Replace);\r
         return (EFI_BUFFER_TOO_SMALL);\r
       }\r
-      StrnCat(NewString, SourceString, 1);\r
+      StrnCatS(NewString, NewSize/sizeof(CHAR16), SourceString, 1);\r
       SourceString++;\r
     }\r
   }\r
@@ -3254,7 +3263,9 @@ StrnCatGrow (
   if (*Destination == NULL) {\r
     return (NULL);\r
   }\r
-  return StrnCat(*Destination, Source, Count);\r
+  \r
+  StrCatS(*Destination, Count + 1, Source);\r
+  return *Destination;\r
 }\r
 \r
 /**\r
index 7c3f80985352ee073d4adbc705d5991c73be0600..fa00d6c6e9781ff57021d4dc23bdd64668745045 100644 (file)
@@ -2,7 +2,7 @@
   The implementation for ifcommand shell command.\r
 \r
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -251,6 +251,8 @@ GetChildHandle (
   Append OFFSET/WIDTH/VALUE items at the beginning of string.\r
 \r
   @param[in, out]  String      The pointer to the string to append onto.\r
+  @param[in]       MaxLen      The max number of UNICODE char in String\r
+                               including the terminate NULL char.\r
   @param[in]       Offset      Offset value.\r
   @param[in]       Width       Width value.\r
   @param[in]       Block       Point to data buffer.\r
@@ -261,6 +263,7 @@ UINTN
 EFIAPI\r
 AppendOffsetWidthValue (\r
   IN OUT CHAR16               *String,\r
+  IN UINTN                    MaxLen,\r
   IN UINTN                    Offset,\r
   IN UINTN                    Width,\r
   IN CONST UINT8              *Block\r
@@ -271,16 +274,16 @@ AppendOffsetWidthValue (
 \r
   OriString = String;\r
 \r
-  StrnCpy (String, L"&OFFSET=", 9);\r
+  StrnCpyS (String, MaxLen, L"&OFFSET=", 9);\r
   String += StrLen (L"&OFFSET=");\r
   String += UnicodeSPrint (String, 20, L"%x", Offset);\r
 \r
-  StrnCpy (String,L"&WIDTH=", 8);\r
+  StrnCpyS (String, MaxLen, L"&WIDTH=", 8);\r
   String += StrLen (L"&WIDTH=");\r
   String += UnicodeSPrint (String, 20, L"%x", Width);\r
 \r
   if (Block != NULL) {\r
-    StrnCpy (String,L"&VALUE=", 8);\r
+    StrnCpyS (String, MaxLen, L"&VALUE=", 8);\r
     String += StrLen (L"&VALUE=");\r
     while ((Width--) != 0) {\r
       String += UnicodeSPrint (String, 20, L"%x", Block[Width]);\r
@@ -342,6 +345,7 @@ ConstructConfigHdr (
 {\r
   EFI_STATUS                 Status;\r
   CHAR16                     *ConfigHdr;\r
+  UINTN                      ConfigHdrBufferSize;\r
   EFI_DEVICE_PATH_PROTOCOL   *DevicePath;\r
   CHAR16                     *String;\r
   UINTN                      Index;\r
@@ -363,13 +367,14 @@ ConstructConfigHdr (
 \r
   DevicePathLength = GetDevicePathSize (DevicePath);\r
   NameLength = StrLen (Name);\r
-  ConfigHdr = AllocateZeroPool ((5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathLength * 2 + 1) * sizeof (CHAR16));\r
+  ConfigHdrBufferSize = (5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathLength * 2 + 1) * sizeof (CHAR16);\r
+  ConfigHdr = AllocateZeroPool (ConfigHdrBufferSize);\r
   if (ConfigHdr == NULL) {\r
     return NULL;\r
   } \r
 \r
   String = ConfigHdr;\r
-  StrnCpy (String, L"GUID=", 6);\r
+  StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"GUID=", 6);\r
   String += StrLen (L"GUID=");\r
 \r
   //\r
@@ -382,7 +387,7 @@ ConstructConfigHdr (
   //\r
   // Append L"&NAME="\r
   //\r
-  StrnCpy (String, L"&NAME=", 7);\r
+  StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"&NAME=", 7);\r
   String += StrLen (L"&NAME=");\r
   for (Index = 0; Index < NameLength ; Index++) {\r
     String += UnicodeSPrint (String, 10, L"00%x", Name[Index]);\r
@@ -391,7 +396,7 @@ ConstructConfigHdr (
   //\r
   // Append L"&PATH="\r
   //\r
-  StrnCpy (String, L"&PATH=", 7);\r
+  StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"&PATH=", 7);\r
   String += StrLen (L"&PATH=");\r
   for (Index = 0, Buffer = (UINT8 *) DevicePath; Index < DevicePathLength; Index++) {\r
     String += UnicodeSPrint (String, 6, L"%02x", *Buffer++);\r
@@ -548,6 +553,7 @@ IfconfigGetAllNicInfoByHii (
   EFI_HANDLE                    *Handles;\r
   UINTN                         HandleCount;\r
   CHAR16                        *ConfigResp;\r
+  UINTN                         ConfigRespBufferSize;\r
   CHAR16                        *ConfigHdr;\r
   UINTN                         Index;\r
   CHAR16                        *AccessProgress;\r
@@ -612,13 +618,14 @@ IfconfigGetAllNicInfoByHii (
     } else {\r
       Length = 0;\r
     }\r
-    ConfigResp = AllocateZeroPool ((Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16));\r
+    ConfigRespBufferSize = (Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16);\r
+    ConfigResp = AllocateZeroPool (ConfigRespBufferSize);\r
     if (ConfigResp == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto ON_ERROR;\r
     }\r
     if (ConfigHdr != NULL) {\r
-      StrnCpy (ConfigResp, ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);\r
+      StrnCpyS (ConfigResp, ConfigRespBufferSize/sizeof(CHAR16), ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);\r
     }\r
  \r
     //\r
@@ -626,7 +633,12 @@ IfconfigGetAllNicInfoByHii (
     //\r
     String = ConfigResp + Length;\r
     Offset = 0;\r
-    AppendOffsetWidthValue (String, Offset, NIC_ITEM_CONFIG_SIZE, NULL);\r
+    AppendOffsetWidthValue (String, \r
+                            ConfigRespBufferSize/sizeof(CHAR16) - Length, \r
+                            Offset, \r
+                            NIC_ITEM_CONFIG_SIZE, \r
+                            NULL\r
+                            );\r
 \r
     NicInfo = AllocateZeroPool (sizeof (NIC_INFO));\r
     if (NicInfo == NULL) {\r
@@ -754,6 +766,7 @@ IfconfigSetNicAddrByHii (
   SHELL_STATUS                  ShellStatus;\r
   NIC_IP4_CONFIG_INFO           *NicConfig;\r
   CHAR16                        *ConfigResp;\r
+  UINTN                         ConfigRespBufferSize;\r
   CHAR16                        *ConfigHdr;\r
   CHAR16                        *AccessProgress;\r
   CHAR16                        *AccessResults;\r
@@ -785,13 +798,14 @@ IfconfigSetNicAddrByHii (
     ShellStatus = SHELL_OUT_OF_RESOURCES;\r
     goto ON_EXIT;\r
   }\r
-  ConfigResp = AllocateZeroPool ((Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16));\r
+  ConfigRespBufferSize = (Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16);\r
+  ConfigResp = AllocateZeroPool (ConfigRespBufferSize);\r
   if (ConfigResp == NULL) {\r
     ShellStatus = SHELL_OUT_OF_RESOURCES;\r
     goto ON_EXIT;\r
   }\r
   if (ConfigHdr != NULL) {\r
-    StrnCpy (ConfigResp, ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);\r
+    StrnCpyS (ConfigResp, ConfigRespBufferSize/sizeof(CHAR16), ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);\r
   }\r
 \r
   NicConfig = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r
@@ -809,7 +823,12 @@ IfconfigSetNicAddrByHii (
   //\r
   String = ConfigResp + Length;\r
   Offset = 0;\r
-  AppendOffsetWidthValue (String, Offset, NIC_ITEM_CONFIG_SIZE, NULL);\r
+  AppendOffsetWidthValue (String, \r
+                          ConfigRespBufferSize/sizeof(CHAR16) - Length,\r
+                          Offset, \r
+                          NIC_ITEM_CONFIG_SIZE, \r
+                          NULL\r
+                          );\r
 \r
   //\r
   // Call HII helper function to generate configuration string\r