]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootOption.c
IntelFrameworkModulePkg BootMaint: Use safe string functions
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / BootMaint / BootOption.c
index 0a6a445f0b635f46c366504d9b0d6877c5bd776e..1519315d40007403bb9ea9bf2f06f2781d4b773c 100644 (file)
@@ -5,7 +5,7 @@
 \r
   Boot option manipulation\r
 \r
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 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
@@ -1010,11 +1010,9 @@ BOpt_GetBootOptions (
     \r
     StringSize = StrSize((UINT16*)LoadOptionPtr);\r
 \r
-    NewLoadContext->Description = AllocateZeroPool (StrSize((UINT16*)LoadOptionPtr));\r
-    ASSERT (NewLoadContext->Description != NULL);\r
-    StrCpy (NewLoadContext->Description, (UINT16*)LoadOptionPtr);\r
-    \r
+    NewLoadContext->Description = AllocateCopyPool (StrSize((UINT16*)LoadOptionPtr), LoadOptionPtr);\r
     ASSERT (NewLoadContext->Description != NULL);\r
+\r
     NewMenuEntry->DisplayString = NewLoadContext->Description;\r
 \r
     LoadOptionPtr += StringSize;\r
@@ -1089,6 +1087,7 @@ BOpt_AppendFileName (
 {\r
   UINTN   Size1;\r
   UINTN   Size2;\r
+  UINTN   MaxLen;\r
   CHAR16  *Str;\r
   CHAR16  *TmpStr;\r
   CHAR16  *Ptr;\r
@@ -1096,18 +1095,18 @@ BOpt_AppendFileName (
 \r
   Size1 = StrSize (Str1);\r
   Size2 = StrSize (Str2);\r
-  Str   = AllocateZeroPool (Size1 + Size2 + sizeof (CHAR16));\r
+  MaxLen = (Size1 + Size2 + sizeof (CHAR16)) / sizeof (CHAR16);\r
+  Str   = AllocateCopyPool (MaxLen * sizeof (CHAR16), Str1);\r
   ASSERT (Str != NULL);\r
 \r
-  TmpStr = AllocateZeroPool (Size1 + Size2 + sizeof (CHAR16)); \r
+  TmpStr = AllocateZeroPool (MaxLen * sizeof (CHAR16)); \r
   ASSERT (TmpStr != NULL);\r
 \r
-  StrCat (Str, Str1);\r
   if (!((*Str == '\\') && (*(Str + 1) == 0))) {\r
-    StrCat (Str, L"\\");\r
+    StrCatS (Str, MaxLen, L"\\");\r
   }\r
 \r
-  StrCat (Str, Str2);\r
+  StrCatS (Str, MaxLen, Str2);\r
 \r
   Ptr       = Str;\r
   LastSlash = Str;\r
@@ -1120,11 +1119,11 @@ BOpt_AppendFileName (
       //\r
 \r
       //\r
-      // Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings \r
+      // Use TmpStr as a backup, as StrCpyS in BaseLib does not handle copy of two strings \r
       // that overlap.\r
       //\r
-      StrCpy (TmpStr, Ptr + 3);\r
-      StrCpy (LastSlash, TmpStr);\r
+      StrCpyS (TmpStr, MaxLen, Ptr + 3);\r
+      StrCpyS (LastSlash, MaxLen - (UINTN) (LastSlash - Str), TmpStr);\r
       Ptr = LastSlash;\r
     } else if (*Ptr == '\\' && *(Ptr + 1) == '.' && *(Ptr + 2) == '\\') {\r
       //\r
@@ -1132,11 +1131,11 @@ BOpt_AppendFileName (
       //\r
 \r
       //\r
-      // Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings \r
+      // Use TmpStr as a backup, as StrCpyS in BaseLib does not handle copy of two strings \r
       // that overlap.\r
       //\r
-      StrCpy (TmpStr, Ptr + 2);\r
-      StrCpy (Ptr, TmpStr);\r
+      StrCpyS (TmpStr, MaxLen, Ptr + 2);\r
+      StrCpyS (Ptr, MaxLen - (UINTN) (Ptr - Str), TmpStr);\r
       Ptr = LastSlash;\r
     } else if (*Ptr == '\\') {\r
       LastSlash = Ptr;\r