]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelFrameworkModulePkg BootMaint: Use safe string functions
authorHao Wu <hao.a.wu@intel.com>
Tue, 30 Jun 2015 06:27:18 +0000 (06:27 +0000)
committerhwu1225 <hwu1225@Edk2>
Tue, 30 Jun 2015 06:27:18 +0000 (06:27 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17736 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootOption.c
IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/FormGuid.h
IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c
IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.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
index f2e1866845b8741bfcc2f6f1e6b03b992210033a..bf99999760076f2097ac32d761ba1ba102218b04 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Formset guids, form id and VarStore data structure for Boot Maintenance Manager.\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
@@ -219,14 +219,20 @@ typedef struct {
 #define KEY_VALUE_SAVE_AND_EXIT_DRIVER         0x1002\r
 #define KEY_VALUE_NO_SAVE_AND_EXIT_DRIVER      0x1003\r
 \r
+//\r
+// Description data and optional data size\r
+//\r
+#define DESCRIPTION_DATA_SIZE                  75\r
+#define OPTIONAL_DATA_SIZE                     127\r
+\r
 ///\r
 /// This is the data structure used by File Explorer formset\r
 ///\r
 typedef struct {\r
-  UINT16  BootDescriptionData[75];\r
-  UINT16  BootOptionalData[127];\r
-  UINT16  DriverDescriptionData[75];\r
-  UINT16  DriverOptionalData[127];\r
+  UINT16  BootDescriptionData[DESCRIPTION_DATA_SIZE];\r
+  UINT16  BootOptionalData[OPTIONAL_DATA_SIZE];\r
+  UINT16  DriverDescriptionData[DESCRIPTION_DATA_SIZE];\r
+  UINT16  DriverOptionalData[OPTIONAL_DATA_SIZE];\r
   BOOLEAN BootOptionChanged;\r
   BOOLEAN DriverOptionChanged;\r
   UINT8   Active;\r
index 7d5861e9fe8e319082558ec7e43ef378b4fcda2e..b13ed116303b0e948da132e062b0b55819f3bd23 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Dynamically update the pages.\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
@@ -830,7 +830,7 @@ UpdateConModePage (
     //\r
     UnicodeValueToString (ModeString, 0, Col, 0);\r
     PStr = &ModeString[0];\r
-    StrnCat (PStr, L" x ", StrLen(L" x ") + 1);\r
+    StrCatS (PStr, sizeof (ModeString) / sizeof (ModeString[0]), L" x ");\r
     PStr = PStr + StrLen (PStr);\r
     UnicodeValueToString (PStr , 0, Row, 0);\r
 \r
index e4299ff6cb9aa3d40b253788c4bc61a9b945984b..616549e64a223f505a6de112695984680f744338 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Variable operation that will be used by bootmaint\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
@@ -579,7 +579,7 @@ Var_UpdateDriverOption (
     );\r
 \r
   if (*DescriptionData == 0x0000) {\r
-    StrCpy (DescriptionData, DriverString);\r
+    StrCpyS (DescriptionData, DESCRIPTION_DATA_SIZE, DriverString);\r
   }\r
 \r
   BufferSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (DescriptionData);\r
@@ -763,7 +763,11 @@ Var_UpdateBootOption (
   UnicodeSPrint (BootString, sizeof (BootString), L"Boot%04x", Index);\r
 \r
   if (NvRamMap->BootDescriptionData[0] == 0x0000) {\r
-    StrCpy (NvRamMap->BootDescriptionData, BootString);\r
+    StrCpyS (\r
+      NvRamMap->BootDescriptionData,\r
+      sizeof (NvRamMap->BootDescriptionData) / sizeof (NvRamMap->BootDescriptionData[0]),\r
+      BootString\r
+      );\r
   }\r
 \r
   BufferSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (NvRamMap->BootDescriptionData);\r