]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiHiiLib/HiiLib.c
MdeModulePkg:Use safe string functions
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLib.c
index 7ae5c4c0776898991199104f9f1e61fcd7b4296a..bee5e0d22cfabcbba1f20280deadf489e3b26edf 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   HII Library implementation that uses DXE protocols and services.\r
 \r
-  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 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
@@ -606,6 +606,7 @@ HiiConstructConfigHdr (
   CHAR16                    *ReturnString;\r
   UINTN                     Index;\r
   UINT8                     *Buffer;\r
+  UINTN                     MaxLen;\r
 \r
   //\r
   // Compute the length of Name in Unicode characters.  \r
@@ -636,7 +637,8 @@ HiiConstructConfigHdr (
   // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>\r
   // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |\r
   //\r
-  String = AllocateZeroPool ((5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathSize * 2 + 1) * sizeof (CHAR16));\r
+  MaxLen = 5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathSize * 2 + 1;\r
+  String = AllocateZeroPool (MaxLen * sizeof (CHAR16));\r
   if (String == NULL) {\r
     return NULL;\r
   }\r
@@ -644,7 +646,8 @@ HiiConstructConfigHdr (
   //\r
   // Start with L"GUID="\r
   //\r
-  ReturnString = StrCpy (String, L"GUID=");\r
+  StrCpyS (String, MaxLen, L"GUID=");\r
+  ReturnString = String;\r
   String += StrLen (String);\r
 \r
   if (Guid != NULL) {\r
@@ -659,7 +662,7 @@ HiiConstructConfigHdr (
   //\r
   // Append L"&NAME="\r
   //\r
-  StrCpy (String, L"&NAME=");\r
+  StrCpyS (String, MaxLen, L"&NAME=");\r
   String += StrLen (String);\r
 \r
   if (Name != NULL) {\r
@@ -674,7 +677,7 @@ HiiConstructConfigHdr (
   //\r
   // Append L"&PATH="\r
   //\r
-  StrCpy (String, L"&PATH=");\r
+  StrCpyS (String, MaxLen, L"&PATH=");\r
   String += StrLen (String);\r
 \r
   //\r
@@ -786,7 +789,7 @@ InternalHiiGetBufferFromString (
     StringPtr = (CHAR16 *) DataBuffer;\r
     ZeroMem (TemStr, sizeof (TemStr));\r
     for (Index = 0; Index < Length; Index += 4) {\r
-      StrnCpy (TemStr, ConfigHdr + Index, 4);\r
+      StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), ConfigHdr + Index, 4);\r
       StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr);\r
     }\r
     //\r
@@ -2011,6 +2014,7 @@ InternalHiiIfrValueAction (
 \r
   EFI_HII_PACKAGE_LIST_HEADER  *HiiPackageList;\r
   UINTN                        PackageListLength;\r
+  UINTN                        MaxLen;\r
   EFI_DEVICE_PATH_PROTOCOL     *DevicePath;\r
   EFI_DEVICE_PATH_PROTOCOL     *TempDevicePath;\r
 \r
@@ -2266,14 +2270,15 @@ NextConfigAltResp:
     // Construct ConfigAltHdr string  "&<ConfigHdr>&ALTCFG=\0" \r
     //                               | 1 | StrLen (ConfigHdr) | 8 | 1 |\r
     //\r
-    ConfigAltHdr = AllocateZeroPool ((1 + StringPtr - StringHdr + 8 + 1) * sizeof (CHAR16));\r
+    MaxLen = 1 + StringPtr - StringHdr + 8 + 1;\r
+    ConfigAltHdr = AllocateZeroPool ( MaxLen * sizeof (CHAR16));\r
     if (ConfigAltHdr == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
     }\r
-    StrCpy (ConfigAltHdr, L"&");\r
-    StrnCat (ConfigAltHdr, StringHdr, StringPtr - StringHdr);\r
-    StrCat (ConfigAltHdr, L"&ALTCFG=");\r
+    StrCpyS (ConfigAltHdr, MaxLen, L"&");\r
+    StrnCatS (ConfigAltHdr, MaxLen, StringHdr, StringPtr - StringHdr);\r
+    StrCatS (ConfigAltHdr, MaxLen, L"&ALTCFG=");\r
     \r
     //\r
     // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr\r