Browse Source

Vlv2TbltDevicePkg: Use safe string and PCD functions

Update all modules to use safe string functions from BaseLib
and PcdLib to address build failures.

Cc: Zailiang Sun <zailiang.sun@intel.com>
Cc: Yi Qian <yi.qian@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Zailiang Sun <zailiang.sun@intel.com>
Michael D Kinney 3 years ago
parent
commit
391ef3d7bd
21 changed files with 297 additions and 184 deletions
  1. 6 4
      Platform/Intel/Vlv2TbltDevicePkg/Application/FirmwareUpdate/FirmwareUpdate.c
  2. 3 3
      Platform/Intel/Vlv2TbltDevicePkg/PlatformInitPei/PlatformEarlyInit.c
  3. 20 20
      Platform/Intel/Vlv2TbltDevicePkg/PlatformSetupDxe/PlatformSetupDxe.c
  4. 21 18
      Platform/Intel/Vlv2TbltDevicePkg/PlatformSetupDxe/SetupInfoRecords.c
  5. 21 9
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscBaseBoardManufacturerFunction.c
  6. 13 7
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscBiosVendorFunction.c
  7. 19 9
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscChassisManufacturerFunction.c
  8. 21 9
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscMemoryDeviceFunction.c
  9. 3 3
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscNumberOfInstallableLanguagesFunction.c
  10. 6 4
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscOemStringFunction.c
  11. 19 9
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscOemType0x90Function.c
  12. 69 46
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscOemType0x94Function.c
  13. 6 4
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscOnboardDeviceFunction.c
  14. 7 5
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscPortInternalConnectorDesignatorFunction.c
  15. 2 2
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscProcessorCacheFunction.c
  16. 20 8
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscProcessorInformationFunction.c
  17. 6 4
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscSystemLanguageStringFunction.c
  18. 21 10
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscSystemManufacturerFunction.c
  19. 6 4
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscSystemOptionStringFunction.c
  20. 6 4
      Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscSystemSlotDesignationFunction.c
  21. 2 2
      Platform/Intel/Vlv2TbltDevicePkg/VlvPlatformInitDxe/IgdOpRegion.c

+ 6 - 4
Platform/Intel/Vlv2TbltDevicePkg/Application/FirmwareUpdate/FirmwareUpdate.c

@@ -1,10 +1,12 @@
 /** @file
 
-Copyright (c) 2007  - 2015, Intel Corporation. All rights reserved.<BR>
-                                                                                   

+Copyright (c) 2007  - 2020, Intel Corporation. All rights reserved.<BR>
+                                                                                   
+
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
-                                                                                   

+                                                                                   
+
 
 **/
 
@@ -239,7 +241,7 @@ ParseCommandLine (
         PrintToken (STRING_TOKEN (STR_FWUPDATE_PATH_ERROR), HiiHandle, Argv[Index]);
         return EFI_INVALID_PARAMETER;
       }
-      StrCpy (mInputData.FileName, Argv[Index]);
+      StrCpyS (mInputData.FileName, sizeof (mInputData.FileName) / sizeof (CHAR16), Argv[Index]);
       mInputData.UpdateFromFile = TRUE;
     }
   }

+ 3 - 3
Platform/Intel/Vlv2TbltDevicePkg/PlatformInitPei/PlatformEarlyInit.c

@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2004  - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2004  - 2020, Intel Corporation. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -363,9 +363,9 @@ MeasuredBootInit (
   )
 {
   if (SystemConfiguration->MeasuredBootEnable) {
-    PcdSetBool (PcdMeasuredBootEnable, TRUE);
+    PcdSetBoolS (PcdMeasuredBootEnable, TRUE);
   } else {
-    PcdSetBool (PcdMeasuredBootEnable, FALSE);
+    PcdSetBoolS (PcdMeasuredBootEnable, FALSE);
   }
 
   return EFI_SUCCESS;

+ 20 - 20
Platform/Intel/Vlv2TbltDevicePkg/PlatformSetupDxe/PlatformSetupDxe.c

@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2004  - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2004  - 2020, Intel Corporation. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -236,8 +236,8 @@ SystemConfigCallback (
   case EFI_BROWSER_ACTION_CHANGING:
   {
     if (KeyValue == 0x1235) {
-      StrCpy (StringBuffer1, L"Will you disable PTT ? ");
-      StrCpy (StringBuffer2, L"Enter (YES)  /   Esc (NO)");
+      StrCpyS (StringBuffer1, 200, L"Will you disable PTT ? ");
+      StrCpyS (StringBuffer2, 200, L"Enter (YES)  /   Esc (NO)");
 
       //
       // Popup a menu to notice user
@@ -253,8 +253,8 @@ SystemConfigCallback (
 
       }
     } else if (KeyValue == 0x1236) {
-      StrCpy (StringBuffer1, L"Will you revoke trust ? ");
-      StrCpy (StringBuffer2, L"Enter (YES)  /   Esc (NO)");
+      StrCpyS (StringBuffer1, 200, L"Will you revoke trust ? ");
+      StrCpyS (StringBuffer2, 200, L"Enter (YES)  /   Esc (NO)");
 
       //
       // Popup a menu to notice user
@@ -271,9 +271,9 @@ SystemConfigCallback (
       }
 	 } else if (KeyValue == 0x1239) {
 	   if (Value->u8 == 0x00) {
-       StrCpy (StringBuffer1, L"WARNING: SOC may be damaged due to high temperature");
-       StrCpy (StringBuffer2, L"when DPTF is disabled and IGD turbo is enabled.");
-       StrCpy (StringBuffer3, L"Press Enter/ESC to continue...");
+       StrCpyS (StringBuffer1, 200, L"WARNING: SOC may be damaged due to high temperature");
+       StrCpyS (StringBuffer2, 200, L"when DPTF is disabled and IGD turbo is enabled.");
+       StrCpyS (StringBuffer3, 200, L"Press Enter/ESC to continue...");
 
         //
         // Popup a menu to notice user
@@ -286,9 +286,9 @@ SystemConfigCallback (
 	    //
       // Popup a menu to notice user
       //
-      StrCpy (StringBuffer1, L"WARNING: All your data on the eMMC will be lost");
-      StrCpy (StringBuffer2, L"Do you really want to enable secure erase on eMMC?");
-      StrCpy (StringBuffer3, L"       Enter (YES)    /    Esc (NO)        ");
+      StrCpyS (StringBuffer1, 200, L"WARNING: All your data on the eMMC will be lost");
+      StrCpyS (StringBuffer2, 200, L"Do you really want to enable secure erase on eMMC?");
+      StrCpyS (StringBuffer3, 200, L"       Enter (YES)    /    Esc (NO)        ");
 
       do {
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, StringBuffer3,NULL);
@@ -364,8 +364,8 @@ SystemConfigCallback (
       //
       // Popup a menu to notice user
       //
-      StrCpy (StringBuffer1, L"Do you want to Commit Changes and Exit?");
-      StrCpy (StringBuffer2, L"         Enter (YES) / Esc (NO)        ");
+      StrCpyS (StringBuffer1, 200, L"Do you want to Commit Changes and Exit?");
+      StrCpyS (StringBuffer2, 200, L"         Enter (YES) / Esc (NO)        ");
 
       do {
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
@@ -431,8 +431,8 @@ SystemConfigCallback (
       //
       // Popup a menu to notice user
       //
-      StrCpy (StringBuffer1, L"Do you want to Discard Changes and Exit?");
-      StrCpy (StringBuffer2, L"         Enter (YES) / Esc (NO)         ");
+      StrCpyS (StringBuffer1, 200, L"Do you want to Discard Changes and Exit?");
+      StrCpyS (StringBuffer2, 200, L"         Enter (YES) / Esc (NO)         ");
 
       do {
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
@@ -451,8 +451,8 @@ SystemConfigCallback (
       //
       // Popup a menu to notice user
       //
-      StrCpy (StringBuffer1, L"Do you want to load setup defaults and Exit?");
-      StrCpy (StringBuffer2, L"         Enter (YES) / Esc (NO)             ");
+      StrCpyS (StringBuffer1, 200, L"Do you want to load setup defaults and Exit?");
+      StrCpyS (StringBuffer2, 200, L"         Enter (YES) / Esc (NO)             ");
 
       do {
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
@@ -522,9 +522,9 @@ SystemConfigCallback (
 			   );
       }
     } else if ((KeyValue == 0x123A) || (KeyValue == 0x123B) || (KeyValue == 0x123C)) {
-        StrCpy (StringBuffer1, L"WARNING: Enable or disable USB Controllers will ");
-        StrCpy (StringBuffer2, L"make global reset to restart system.");
-        StrCpy (StringBuffer3, L"Press Enter/ESC to continue...");
+        StrCpyS (StringBuffer1, 200, L"WARNING: Enable or disable USB Controllers will ");
+        StrCpyS (StringBuffer2, 200, L"make global reset to restart system.");
+        StrCpyS (StringBuffer3, 200, L"Press Enter/ESC to continue...");
         //
         // Popup a menu to notice user
         //

+ 21 - 18
Platform/Intel/Vlv2TbltDevicePkg/PlatformSetupDxe/SetupInfoRecords.c

@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2004  - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2004  - 2020, Intel Corporation. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -138,7 +138,7 @@ GetOptionalStringByIndex (
     return EFI_NOT_FOUND;
   } else {
     *String = AllocatePool (StrSize * sizeof (CHAR16));
-    AsciiStrToUnicodeStr (OptionalStrStart, *String);
+    AsciiStrToUnicodeStrS (OptionalStrStart, *String, StrSize);
   }
 
   return EFI_SUCCESS;
@@ -418,9 +418,9 @@ PrepareSetupInformation (
     Length = StrLen(ReleaseDate) + StrLen(ReleaseTime);
 
     BuildDateTime = AllocateZeroPool ((Length+2) * sizeof(CHAR16));
-    StrCpy (BuildDateTime, ReleaseDate);
-    StrCat (BuildDateTime, L" ");
-    StrCat (BuildDateTime, ReleaseTime);
+    StrCpyS (BuildDateTime, Length + 2, ReleaseDate);
+    StrCatS (BuildDateTime, Length + 2, L" ");
+    StrCatS (BuildDateTime, Length + 2, ReleaseTime);
 
     TokenToUpdate = (STRING_REF)STR_BIOS_VERSION_VALUE;
     DEBUG ((EFI_D_ERROR, "update STR_BIOS_VERSION_VALUE\n"));
@@ -991,7 +991,7 @@ UpdatePlatformInformation (
   MrcVersion = 0x00000000;
   MrcVersion &= 0xffff;
   Index = EfiValueToString (Buffer, MrcVersion/100, PREFIX_ZERO, 0);
-  StrCat (Buffer, L".");
+  StrCatS (Buffer, sizeof (Buffer) / sizeof (CHAR16), L".");
   EfiValueToString (Buffer + Index + 1, (MrcVersion%100)/10, PREFIX_ZERO, 0);
   EfiValueToString (Buffer + Index + 2, (MrcVersion%100)%10, PREFIX_ZERO, 0);
   HiiSetString(mHiiHandle,STRING_TOKEN(STR_MRC_VERSION_VALUE), Buffer, NULL);
@@ -1081,15 +1081,16 @@ UpdatePlatformInformation (
 VOID
 GetDeviceSpeedString (
   CHAR16                      *NewString,
+  UINTN                       NewStringSize,
   IN UINTN                    DeviceSpeed
   )
 {
   if (DeviceSpeed == 0x01) {
-    StrCat (NewString, L"1.5Gb/s");
+    StrCatS (NewString, NewStringSize, L"1.5Gb/s");
   } else if (DeviceSpeed == 0x02) {
-    StrCat (NewString, L"3.0Gb/s");
+    StrCatS (NewString, NewStringSize, L"3.0Gb/s");
   } else if (DeviceSpeed == 0x03) {
-    StrCat (NewString, L"6.0Gb/s");
+    StrCatS (NewString, NewStringSize, L"6.0Gb/s");
   } else if (DeviceSpeed == 0x0) {
 
   }
@@ -1206,6 +1207,7 @@ IdeDataFilter (void)
   UINT32                      IdeDevice;
   EFI_ATA_IDENTIFY_DATA       *IdentifyDriveInfo;
   CHAR16                      *NewString;
+  UINTN                       NewStringSize;
   CHAR16                      SizeString[20];
   STRING_REF                  NameToUpdate;
   CHAR8                       StringBuffer[0x100];
@@ -1216,6 +1218,7 @@ IdeDataFilter (void)
   // Assume no line strings is longer than 256 bytes.
   //
   NewString = AllocateZeroPool (0x100);
+  NewStringSize = 0x100 / sizeof (CHAR16);
   PciDevicePath = NULL;
 
   //
@@ -1334,15 +1337,15 @@ IdeDataFilter (void)
           DriveSize = (UINT32) DivU64x32(MultU64x32(DivU64x32(DriveSize, 1000), 512), 1000);
         }
 
-        StrCat (NewString, L"(");
+        StrCatS (NewString, NewStringSize, L"(");
         EfiValueToString (SizeString, DriveSize/1000, PREFIX_BLANK, 0);
-        StrCat (NewString, SizeString);
-        StrCat (NewString, L".");
+        StrCatS (NewString, NewStringSize, SizeString);
+        StrCatS (NewString, NewStringSize, L".");
         EfiValueToString (SizeString, (DriveSize%1000)/100, PREFIX_BLANK, 0);
-        StrCat (NewString, SizeString);
-        StrCat (NewString, L"GB");
+        StrCatS (NewString, NewStringSize, SizeString);
+        StrCatS (NewString, NewStringSize, L"GB");
       } else {
-        StrCat (NewString, L"(ATAPI");
+        StrCatS (NewString, NewStringSize, L"(ATAPI");
       }
 
       //
@@ -1352,11 +1355,11 @@ IdeDataFilter (void)
       DeviceSpeed = GetChipsetSataPortSpeed(PortNumber);
 
       if (DeviceSpeed) {
-        StrCat (NewString, L"-");
-        GetDeviceSpeedString( NewString, DeviceSpeed);
+        StrCatS (NewString, NewStringSize, L"-");
+        GetDeviceSpeedString( NewString, NewStringSize, DeviceSpeed);
       }
 
-      StrCat (NewString, L")");
+      StrCatS (NewString, NewStringSize, L")");
 
       HiiSetString(mHiiHandle, NameToUpdate, NewString, NULL);
 

+ 21 - 9
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscBaseBoardManufacturerFunction.c

@@ -1,6 +1,6 @@
 /*++
 
-Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -40,6 +40,7 @@ extern EFI_PLATFORM_INFO_HOB *mPlatformInfo;
 MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
 {
   CHAR8                           *OptionalStrStart;
+  UINTN                           OptionalStrSize;
   UINTN                           ManuStrLen;
   UINTN                           ProductStrLen;
   UINTN                           VerStrLen;
@@ -167,8 +168,9 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
   //
   // Two zeros following the last string.
   //
-  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE2) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1);
-  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE2) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1);
+  OptionalStrSize = ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1;
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE2) + OptionalStrSize);
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE2) + OptionalStrSize);
 
   SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION;
   SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE2);
@@ -217,12 +219,22 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
   //
   // Since we fill NumberOfContainedObjectHandles = 0 for simple, just after this filed to fill string
   //
-  UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);
-  UnicodeStrToAsciiStr(Product, OptionalStrStart + ManuStrLen + 1);
-  UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1);
-  UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1);
-  UnicodeStrToAsciiStr(AssertTag, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);
-  UnicodeStrToAsciiStr(Chassis, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1);
+  UnicodeStrToAsciiStrS (Manufacturer, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (ManuStrLen + 1);
+  OptionalStrSize  -= (ManuStrLen + 1);
+  UnicodeStrToAsciiStrS (Product, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (ProductStrLen + 1);
+  OptionalStrSize  -= (ProductStrLen + 1);
+  UnicodeStrToAsciiStrS (Version, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (VerStrLen + 1);
+  OptionalStrSize  -= (VerStrLen + 1);
+  UnicodeStrToAsciiStrS (SerialNumber, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (SerialNumStrLen + 1);
+  OptionalStrSize  -= (SerialNumStrLen + 1);
+  UnicodeStrToAsciiStrS (AssertTag, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (AssertTagStrLen + 1);
+  OptionalStrSize  -= (AssertTagStrLen + 1);
+  UnicodeStrToAsciiStrS (Chassis, OptionalStrStart, OptionalStrSize);
 
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.

+ 13 - 7
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscBiosVendorFunction.c

@@ -1,6 +1,6 @@
 /*++
 
-Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -148,6 +148,7 @@ Base2ToByteWith64KUnit (
 MISC_SMBIOS_TABLE_FUNCTION(MiscBiosVendor)
 {
   CHAR8                 *OptionalStrStart;
+  UINTN                 OptionalStrSize;
   UINTN                 VendorStrLen;
   UINTN                 VerStrLen;
   UINTN                 DateStrLen;
@@ -203,7 +204,7 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscBiosVendor)
   Version = SmbiosMiscGetString (TokenToGet);
 
   ZeroMem (BIOSVersionTemp, sizeof (BIOSVersionTemp));
-  StrCat (BIOSVersionTemp,Version);
+  StrCatS (BIOSVersionTemp, sizeof (BIOSVersionTemp) / sizeof (CHAR16), Version);
   VerStrLen = StrLen(BIOSVersionTemp);
   if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
     return EFI_UNSUPPORTED;
@@ -219,8 +220,9 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscBiosVendor)
   //
   // Two zeros following the last string.
   //
-  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE0) + VendorStrLen + 1 + VerStrLen + 1 + DateStrLen + 1 + 1);
-  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE0) + VendorStrLen + 1 + VerStrLen + 1 + DateStrLen + 1 + 1);
+  OptionalStrSize = VendorStrLen + 1 + VerStrLen + 1 + DateStrLen + 1 + 1;
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE0) + OptionalStrSize);
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE0) + OptionalStrSize);
 
   SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BIOS_INFORMATION;
   SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);
@@ -264,9 +266,13 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscBiosVendor)
   SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = ForType0InputData->BiosEmbeddedFirmwareMinorRelease;
 
   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-  UnicodeStrToAsciiStr(Char16String, OptionalStrStart);
-  UnicodeStrToAsciiStr(BIOSVersionTemp, OptionalStrStart + VendorStrLen + 1);
-  UnicodeStrToAsciiStr(ReleaseDate, OptionalStrStart + VendorStrLen + 1 + VerStrLen + 1);
+  UnicodeStrToAsciiStrS(Char16String, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (VendorStrLen + 1);
+  OptionalStrSize  -= (VendorStrLen + 1);
+  UnicodeStrToAsciiStrS(BIOSVersionTemp, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (VerStrLen + 1);
+  OptionalStrSize  -= (VerStrLen + 1);
+  UnicodeStrToAsciiStrS(ReleaseDate, OptionalStrStart, OptionalStrSize);
 
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.

+ 19 - 9
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscChassisManufacturerFunction.c

@@ -1,10 +1,12 @@
 /*++
 
-Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
-                                                                                   

+Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
+                                                                                   
+
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
-                                                                                   

+                                                                                   
+
 
 
 Module Name:
@@ -40,6 +42,7 @@ extern EFI_PLATFORM_INFO_HOB *mPlatformInfo;
 MISC_SMBIOS_TABLE_FUNCTION(MiscChassisManufacturer)
 {
   CHAR8                           *OptionalStrStart;
+  UINTN                           OptionalStrSize;
   UINTN                           ManuStrLen;
   UINTN                           VerStrLen;
   UINTN                           AssertTagStrLen;
@@ -99,8 +102,9 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscChassisManufacturer)
   //
   // Two zeros following the last string.
   //
-  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1  + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1);
-  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1  + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1);
+  OptionalStrSize = ManuStrLen + 1  + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1;
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE3) + OptionalStrSize);
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE3) + OptionalStrSize);
 
   SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE;
   SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE3);
@@ -137,10 +141,16 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscChassisManufacturer)
   CopyMem (SmbiosRecord->OemDefined,(UINT8*)&ForType3InputData->ChassisOemDefined, 4);
 
   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-  UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);
-  UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1);
-  UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1);
-  UnicodeStrToAsciiStr(AssertTag, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);
+  UnicodeStrToAsciiStrS(Manufacturer, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (ManuStrLen + 1);
+  OptionalStrSize  -= (ManuStrLen + 1);
+  UnicodeStrToAsciiStrS(Version, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (VerStrLen + 1);
+  OptionalStrSize  -= (VerStrLen + 1);
+  UnicodeStrToAsciiStrS(SerialNumber, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (SerialNumStrLen + 1);
+  OptionalStrSize  -= (SerialNumStrLen + 1);
+  UnicodeStrToAsciiStrS(AssertTag, OptionalStrStart, OptionalStrSize);
 
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.

+ 21 - 9
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscMemoryDeviceFunction.c

@@ -1,6 +1,6 @@
 /*++
 
-Copyright (c) 2006  - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006  - 2020, Intel Corporation. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -81,6 +81,7 @@ GetType16Hndl (
 MISC_SMBIOS_TABLE_FUNCTION( MiscMemoryDevice )
 {
     CHAR8                           *OptionalStrStart;
+    UINTN                           OptionalStrSize;
     UINTN                           MemDeviceStrLen;
     UINTN                           MemBankLocatorStrLen;
     UINTN                           MemManufacturerStrLen;
@@ -246,8 +247,9 @@ MISC_SMBIOS_TABLE_FUNCTION( MiscMemoryDevice )
       //
       // Two zeros following the last string.
       //
-      SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE17) + MemDeviceStrLen + 1 + MemBankLocatorStrLen + 1 + MemManufacturerStrLen + 1 + MemSerialNumberStrLen + 1 + MemAssetTagStrLen+1 + MemPartNumberStrLen + 1 + 1);
-      ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE17) +  MemDeviceStrLen + 1 + MemBankLocatorStrLen + 1 + MemManufacturerStrLen + 1 + MemSerialNumberStrLen + 1 + MemAssetTagStrLen+1 + MemPartNumberStrLen + 1 + 1);
+      OptionalStrSize = MemDeviceStrLen + 1 + MemBankLocatorStrLen + 1 + MemManufacturerStrLen + 1 + MemSerialNumberStrLen + 1 + MemAssetTagStrLen+1 + MemPartNumberStrLen + 1 + 1;
+      SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE17) + OptionalStrSize);
+      ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE17) +  OptionalStrSize);
 
       SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_MEMORY_DEVICE;
       SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE17);
@@ -287,12 +289,22 @@ MISC_SMBIOS_TABLE_FUNCTION( MiscMemoryDevice )
       SmbiosRecord->MemoryType = MemoryType;
 
       OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-      UnicodeStrToAsciiStr(MemDevice, OptionalStrStart);
-      UnicodeStrToAsciiStr(MemBankLocator, OptionalStrStart + MemDeviceStrLen + 1);
-      UnicodeStrToAsciiStr(MemManufacturer, OptionalStrStart + MemDeviceStrLen + 1 + MemBankLocatorStrLen + 1);
-      UnicodeStrToAsciiStr(MemSerialNumber, OptionalStrStart + MemDeviceStrLen + 1 + MemBankLocatorStrLen + 1 + MemManufacturerStrLen + 1);
-      UnicodeStrToAsciiStr(MemAssetTag, OptionalStrStart + MemDeviceStrLen + 1 + MemBankLocatorStrLen + 1 + MemManufacturerStrLen + 1 + MemSerialNumberStrLen + 1);
-      UnicodeStrToAsciiStr(MemPartNumber, OptionalStrStart + MemDeviceStrLen + 1 + MemBankLocatorStrLen + 1 + MemManufacturerStrLen + 1 + MemSerialNumberStrLen + 1+ MemAssetTagStrLen+1 );
+      UnicodeStrToAsciiStrS (MemDevice, OptionalStrStart, OptionalStrSize);
+      OptionalStrStart += (MemDeviceStrLen + 1);
+      OptionalStrSize  -= (MemDeviceStrLen + 1);
+      UnicodeStrToAsciiStrS (MemBankLocator, OptionalStrStart, OptionalStrSize);
+      OptionalStrStart += (MemBankLocatorStrLen + 1);
+      OptionalStrSize  -= (MemBankLocatorStrLen + 1);
+      UnicodeStrToAsciiStrS (MemManufacturer, OptionalStrStart, OptionalStrSize);
+      OptionalStrStart += (MemManufacturerStrLen + 1);
+      OptionalStrSize  -= (MemManufacturerStrLen + 1);
+      UnicodeStrToAsciiStrS (MemSerialNumber, OptionalStrStart, OptionalStrSize);
+      OptionalStrStart += (MemSerialNumberStrLen + 1);
+      OptionalStrSize  -= (MemSerialNumberStrLen + 1);
+      UnicodeStrToAsciiStrS (MemAssetTag, OptionalStrStart, OptionalStrSize);
+      OptionalStrStart += (MemAssetTagStrLen + 1);
+      OptionalStrSize  -= (MemAssetTagStrLen + 1);
+      UnicodeStrToAsciiStrS (MemPartNumber, OptionalStrStart, OptionalStrSize);
 
       //
       // Now we have got the full smbios record, call smbios protocol to add this record.

+ 3 - 3
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscNumberOfInstallableLanguagesFunction.c

@@ -1,6 +1,6 @@
 /*++
 
-Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
 
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -56,7 +56,7 @@ CurrentLanguageMatch (
     return;
   }
 
-  CurrentLang  = GetEfiGlobalVariable (L"PlatformLang");
+  GetEfiGlobalVariable2 (L"PlatformLang", &CurrentLang, NULL);
   DefaultLang  = (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang);
   BestLanguage = GetBestLanguage (
                    Languages,
@@ -234,7 +234,7 @@ MISC_SMBIOS_TABLE_FUNCTION(NumberOfInstallableLanguages)
   SmbiosRecord->Flags = (UINT8)ForType13InputData->LanguageFlags.AbbreviatedLanguageFormat;
   SmbiosRecord->CurrentLanguages = 1;
   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-  AsciiStrCpy(OptionalStrStart, CurrentLang);
+  AsciiStrCpyS(OptionalStrStart, LangStrLen + 1 + 1, CurrentLang);
 
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.

+ 6 - 4
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscOemStringFunction.c

@@ -1,10 +1,12 @@
 /*++
 
-Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
-                                                                                   

+Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
+                                                                                   
+
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
-                                                                                   

+                                                                                   
+
 
 Module Name:
 
@@ -72,7 +74,7 @@ MISC_SMBIOS_TABLE_FUNCTION(OemString)
   SmbiosRecord->Hdr.Handle = 0;
   SmbiosRecord->StringCount = 1;
   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-  UnicodeStrToAsciiStr(OemStr, OptionalStrStart);
+  UnicodeStrToAsciiStrS (OemStr, OptionalStrStart, OemStrLen + 1 + 1);
 
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.

+ 19 - 9
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscOemType0x90Function.c

@@ -1,10 +1,12 @@
 /*++
 
-Copyright (c) 1999  - 2014, Intel Corporation.  All rights reserved.
-                                                                                   

+Copyright (c) 1999  - 2020, Intel Corporation.  All rights reserved.
+                                                                                   
+
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
-                                                                                   

+                                                                                   
+
 
 
 
@@ -286,6 +288,7 @@ AddSmbiosT0x90Callback (
   CHAR16                *Stepping;
   STRING_REF            TokenToGet;
   CHAR8                 *OptionalStrStart;
+  UINTN                 OptionalStrSize;
   EFI_SMBIOS_PROTOCOL               *SmbiosProtocol;
 
   DEBUG ((EFI_D_INFO, "Executing SMBIOS T0x90 callback.\n"));
@@ -340,8 +343,9 @@ AddSmbiosT0x90Callback (
     return EFI_UNSUPPORTED;
   }
 
-  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE90) + SECVerStrLen + 1 + uCodeVerStrLen + 1 + GOPStrLen + 1 + SteppingStrLen + 1 + 1);
-  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE90) + SECVerStrLen + 1 + uCodeVerStrLen + 1 + GOPStrLen + 1 + SteppingStrLen + 1 + 1);
+  OptionalStrSize = SECVerStrLen + 1 + uCodeVerStrLen + 1 + GOPStrLen + 1 + SteppingStrLen + 1 + 1;
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE90) + OptionalStrSize);
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE90) + OptionalStrSize);
 
   SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_FIRMWARE_VERSION_INFO;
   SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE90);
@@ -372,10 +376,16 @@ AddSmbiosT0x90Callback (
   SmbiosRecord->CpuStepping = 4;
 
   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-  UnicodeStrToAsciiStr(SECVer, OptionalStrStart);
-  UnicodeStrToAsciiStr(uCodeVer, OptionalStrStart + SECVerStrLen + 1);
-  UnicodeStrToAsciiStr(GOPVer, OptionalStrStart + SECVerStrLen + 1 + uCodeVerStrLen + 1);
-  UnicodeStrToAsciiStr(Stepping, OptionalStrStart + SECVerStrLen + 1 + uCodeVerStrLen + 1 + GOPStrLen + 1);
+  UnicodeStrToAsciiStrS (SECVer, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (SECVerStrLen + 1);
+  OptionalStrSize  -= (SECVerStrLen + 1);
+  UnicodeStrToAsciiStrS (uCodeVer, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (uCodeVerStrLen + 1);
+  OptionalStrSize  -= (uCodeVerStrLen + 1);
+  UnicodeStrToAsciiStrS (GOPVer, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (GOPStrLen + 1);
+  OptionalStrSize  -= (GOPStrLen + 1);
+  UnicodeStrToAsciiStrS (Stepping, OptionalStrStart, OptionalStrSize);
 
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.

+ 69 - 46
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscOemType0x94Function.c

@@ -1,6 +1,6 @@
 /*++
 
-Copyright (c) 1999  - 2019, Intel Corporation.  All rights reserved.
+Copyright (c) 1999  - 2020, Intel Corporation.  All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -604,7 +604,7 @@ UpdatePlatformInformation (
   MrcVersion = MmioRead32 (MmPciAddress (0, 0, 0, 0, 0xF0));
   MrcVersion &= 0xffff;
   Index = EfiValueToString (Buffer, MrcVersion/100, PREFIX_ZERO, 0);
-  StrCat (Buffer, L".");
+  StrCatS (Buffer, sizeof (Buffer) / sizeof (CHAR16), L".");
   EfiValueToString (Buffer + Index + 1, (MrcVersion%100)/10, PREFIX_ZERO, 0);
   EfiValueToString (Buffer + Index + 2, (MrcVersion%100)%10, PREFIX_ZERO, 0);
   HiiSetString(mHiiHandle,STRING_TOKEN(STR_MISC_MRC_VERSION_VALUE), Buffer, NULL);
@@ -1064,72 +1064,95 @@ AddSmbiosT0x94Callback (
 
 
   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-  UnicodeStrToAsciiStr(GOPVer, OptionalStrStart);
-  StrIdx +=  GOPStrLen + 1;
+  RecordLen -= sizeof (SMBIOS_TABLE_TYPE94);
+  UnicodeStrToAsciiStrS (GOPVer, OptionalStrStart, RecordLen);
+  StrIdx    += GOPStrLen + 1;
+  RecordLen -= GOPStrLen + 1;
 
-  UnicodeStrToAsciiStr(SECVer, OptionalStrStart + StrIdx);
-  StrIdx +=  SECVerStrLen + 1;
+  UnicodeStrToAsciiStrS (SECVer, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += SECVerStrLen + 1;
+  RecordLen -= SECVerStrLen + 1;
 
-  UnicodeStrToAsciiStr(MrcVer, OptionalStrStart + StrIdx);
-  StrIdx +=  MRCVersionStrLen + 1;
+  UnicodeStrToAsciiStrS (MrcVer, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += MRCVersionStrLen + 1;
+  RecordLen -= MRCVersionStrLen + 1;
 
-  UnicodeStrToAsciiStr(uCodeVer, OptionalStrStart + StrIdx);
-  StrIdx +=  uCodeVerStrLen + 1;
+  UnicodeStrToAsciiStrS (uCodeVer, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += uCodeVerStrLen + 1;
+  RecordLen -= uCodeVerStrLen + 1;
 
-  UnicodeStrToAsciiStr(PunitVer, OptionalStrStart + StrIdx);
-  StrIdx +=  PUNITVersionStrLen + 1;
+  UnicodeStrToAsciiStrS (PunitVer, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += PUNITVersionStrLen + 1;
+  RecordLen -= PUNITVersionStrLen + 1;
 
-  UnicodeStrToAsciiStr(PmcVer, OptionalStrStart + StrIdx);
-  StrIdx +=  PMCVersionStrLen + 1;
+  UnicodeStrToAsciiStrS (PmcVer, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += PMCVersionStrLen + 1;
+  RecordLen -= PMCVersionStrLen + 1;
 
-  UnicodeStrToAsciiStr(UlpmcVer, OptionalStrStart + StrIdx);
-  StrIdx +=  ULPMCVersionStrLen + 1;
+  UnicodeStrToAsciiStrS (UlpmcVer, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += ULPMCVersionStrLen + 1;
+  RecordLen -= ULPMCVersionStrLen + 1;
 
 
-  UnicodeStrToAsciiStr(SocVer, OptionalStrStart + StrIdx);
-  StrIdx +=  SOCVersionStrLen +1;
+  UnicodeStrToAsciiStrS (SocVer, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += SOCVersionStrLen +1;
+  RecordLen -= SOCVersionStrLen +1;
 
-  UnicodeStrToAsciiStr(BoardVer, OptionalStrStart + StrIdx);
-  StrIdx +=  BOARDVersionStrLen + 1;
+  UnicodeStrToAsciiStrS (BoardVer, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += BOARDVersionStrLen + 1;
+  RecordLen -= BOARDVersionStrLen + 1;
 
-  UnicodeStrToAsciiStr(FabVer, OptionalStrStart + StrIdx);
-  StrIdx +=  FABVersionStrLen + 1;
+  UnicodeStrToAsciiStrS (FabVer, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += FABVersionStrLen + 1;
+  RecordLen -= FABVersionStrLen + 1;
 
-  UnicodeStrToAsciiStr(CpuFlavor, OptionalStrStart + StrIdx);
-  StrIdx +=  CPUFLAVORStrLen + 1;
+  UnicodeStrToAsciiStrS (CpuFlavor, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += CPUFLAVORStrLen + 1;
+  RecordLen -= CPUFLAVORStrLen + 1;
 
-  UnicodeStrToAsciiStr(BiosVer, OptionalStrStart + StrIdx);
-  StrIdx +=  BIOSVersionStrLen + 1;
+  UnicodeStrToAsciiStrS (BiosVer, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += BIOSVersionStrLen + 1;
+  RecordLen -= BIOSVersionStrLen + 1;
 
-  UnicodeStrToAsciiStr(PmicVer, OptionalStrStart + StrIdx);
-  StrIdx +=  PMICVersionStrLen + 1;
+  UnicodeStrToAsciiStrS (PmicVer, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += PMICVersionStrLen + 1;
+  RecordLen -= PMICVersionStrLen + 1;
 
-  UnicodeStrToAsciiStr(TouchVer, OptionalStrStart + StrIdx);
-  StrIdx +=  TOUCHVersionStrLen + 1;
+  UnicodeStrToAsciiStrS (TouchVer, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += TOUCHVersionStrLen + 1;
+  RecordLen -= TOUCHVersionStrLen + 1;
 
-  UnicodeStrToAsciiStr(SecureBootMode, OptionalStrStart + StrIdx);
-  StrIdx +=  SecureBootModeLen + 1;
+  UnicodeStrToAsciiStrS (SecureBootMode, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += SecureBootModeLen + 1;
+  RecordLen -= SecureBootModeLen + 1;
 
-  UnicodeStrToAsciiStr(BootMode, OptionalStrStart + StrIdx);
-  StrIdx +=  BootModeLen + 1;
+  UnicodeStrToAsciiStrS (BootMode, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += BootModeLen + 1;
+  RecordLen -= BootModeLen + 1;
 
-  UnicodeStrToAsciiStr(SpeedStepMode, OptionalStrStart + StrIdx);
-  StrIdx +=  SpeedStepModeLen + 1;
+  UnicodeStrToAsciiStrS (SpeedStepMode, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += SpeedStepModeLen + 1;
+  RecordLen -= SpeedStepModeLen + 1;
 
-  UnicodeStrToAsciiStr(CpuTurbo, OptionalStrStart + StrIdx);
-  StrIdx +=  CpuTurboLen + 1;
+  UnicodeStrToAsciiStrS (CpuTurbo, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += CpuTurboLen + 1;
+  RecordLen -= CpuTurboLen + 1;
 
-  UnicodeStrToAsciiStr(MaxCState, OptionalStrStart + StrIdx);
-  StrIdx +=  MaxCStateLen + 1;
+  UnicodeStrToAsciiStrS (MaxCState, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += MaxCStateLen + 1;
+  RecordLen -= MaxCStateLen + 1;
 
-  UnicodeStrToAsciiStr(GfxTurbo, OptionalStrStart + StrIdx);
-  StrIdx +=  GfxTurboLen + 1;
+  UnicodeStrToAsciiStrS (GfxTurbo, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += GfxTurboLen + 1;
+  RecordLen -= GfxTurboLen + 1;
 
-  UnicodeStrToAsciiStr(IdleReserve, OptionalStrStart + StrIdx);
-  StrIdx +=  S0ixLen + 1;
+  UnicodeStrToAsciiStrS (IdleReserve, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += S0ixLen + 1;
+  RecordLen -= S0ixLen + 1;
 
-  UnicodeStrToAsciiStr(RC6, OptionalStrStart + StrIdx);
-  StrIdx +=  RC6Len + 1;
+  UnicodeStrToAsciiStrS (RC6, OptionalStrStart + StrIdx, RecordLen);
+  StrIdx    += RC6Len + 1;
+  RecordLen -= RC6Len + 1;
 
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.

+ 6 - 4
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscOnboardDeviceFunction.c

@@ -1,10 +1,12 @@
 /** @file
 
-Copyright (c) 1999  - 2014, Intel Corporation. All rights reserved.<BR>
-                                                                                   

+Copyright (c) 1999  - 2020, Intel Corporation. All rights reserved.<BR>
+                                                                                   
+
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
-                                                                                   

+                                                                                   
+
 
 
 Module Name:
@@ -118,7 +120,7 @@ MISC_SMBIOS_TABLE_FUNCTION (
   SmbiosRecord->Device[0].DeviceType = StatusAndType;
   SmbiosRecord->Device[0].DescriptionString = 1;
   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-  UnicodeStrToAsciiStr(DeviceDescription, OptionalStrStart);
+  UnicodeStrToAsciiStrS (DeviceDescription, OptionalStrStart, DescriptionStrLen + 1 + 1);
 
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.

+ 7 - 5
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscPortInternalConnectorDesignatorFunction.c

@@ -1,10 +1,12 @@
 /** @file
 
-Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>
-                                                                                   

+Copyright (c) 2004  - 2020, Intel Corporation. All rights reserved.<BR>
+                                                                                   
+
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
-                                                                                   

+                                                                                   
+
 
 
 Module Name:
@@ -134,8 +136,8 @@ MISC_SMBIOS_TABLE_FUNCTION (
   SmbiosRecord->PortType = (UINT8)ForType8InputData->PortType;
 
   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-  UnicodeStrToAsciiStr(InternalRef, OptionalStrStart);
-  UnicodeStrToAsciiStr(ExternalRef, OptionalStrStart + InternalRefStrLen + 1);
+  UnicodeStrToAsciiStrS (InternalRef, OptionalStrStart, InternalRefStrLen + 1 + ExternalRefStrLen + 1 + 1);
+  UnicodeStrToAsciiStrS (ExternalRef, OptionalStrStart + InternalRefStrLen + 1, ExternalRefStrLen + 1 + 1);
 
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.

+ 2 - 2
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscProcessorCacheFunction.c

@@ -1,6 +1,6 @@
 /*++
 
-Copyright (c) 2006  - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006  - 2020, Intel Corporation. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -147,7 +147,7 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscProcessorCache)
 	  //
 	  SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
 	  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-	  UnicodeStrToAsciiStr(SocketDesignation, OptionalStrStart);
+	  UnicodeStrToAsciiStrS (SocketDesignation, OptionalStrStart,  + 7 + 1 + 1);
 
 	  Smbios->Add(
 	            Smbios,

+ 20 - 8
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscProcessorInformationFunction.c

@@ -1,6 +1,6 @@
 /*++
 
-Copyright (c) 2006  - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006  - 2020, Intel Corporation. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -199,6 +199,7 @@ MeasureTscFrequency (
 MISC_SMBIOS_TABLE_FUNCTION (MiscProcessorInformation)
 {
     CHAR8                           *OptionalStrStart;
+    UINTN                           OptionalStrSize;
     EFI_STRING                      SerialNumber;
     CHAR16                          *Version=NULL;
     CHAR16                          *Manufacturer=NULL;
@@ -306,7 +307,8 @@ MISC_SMBIOS_TABLE_FUNCTION (MiscProcessorInformation)
     //
     // Two zeros following the last string.
     //
-    SmbiosRecord = AllocateZeroPool(sizeof (SMBIOS_TABLE_TYPE4) + AssetTagStrLen + 1 + SocketStrLen + 1+ ManufacturerStrLen +1 + VersionStrLen+ 1+ SerialNumberStrLen + 1 + PartNumberStrLen+ 1 + 1);
+    OptionalStrSize = AssetTagStrLen + 1 + SocketStrLen + 1+ ManufacturerStrLen +1 + VersionStrLen+ 1+ SerialNumberStrLen + 1 + PartNumberStrLen+ 1 + 1;
+    SmbiosRecord = AllocateZeroPool(sizeof (SMBIOS_TABLE_TYPE4) + OptionalStrSize);
 
     SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION;
     SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE4);
@@ -421,12 +423,22 @@ MISC_SMBIOS_TABLE_FUNCTION (MiscProcessorInformation)
     SmbiosRecord->L3CacheHandle  = L3CacheHandle;
 
     OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-    UnicodeStrToAsciiStr(Socket, OptionalStrStart);
-    UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart + SocketStrLen + 1);
-    UnicodeStrToAsciiStr(Version, OptionalStrStart + SocketStrLen + 1 + ManufacturerStrLen+ 1);
-    UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + SocketStrLen + 1 + VersionStrLen + 1 + ManufacturerStrLen + 1);
-    UnicodeStrToAsciiStr(AssetTag, OptionalStrStart + SerialNumberStrLen + 1 + VersionStrLen + 1 + ManufacturerStrLen + 1 + SocketStrLen + 1);
-    UnicodeStrToAsciiStr(PartNumber, OptionalStrStart + SerialNumberStrLen + 1 + VersionStrLen + 1 + ManufacturerStrLen + 1 + SocketStrLen + 1 + AssetTagStrLen + 1 );
+    UnicodeStrToAsciiStrS (Socket, OptionalStrStart, OptionalStrSize);
+    OptionalStrStart += (SocketStrLen + 1);
+    OptionalStrSize  -= (SocketStrLen + 1);
+    UnicodeStrToAsciiStrS (Manufacturer, OptionalStrStart, OptionalStrSize);
+    OptionalStrStart += (ManufacturerStrLen + 1);
+    OptionalStrSize  -= (ManufacturerStrLen + 1);
+    UnicodeStrToAsciiStrS (Version, OptionalStrStart, OptionalStrSize);
+    OptionalStrStart += (VersionStrLen + 1);
+    OptionalStrSize  -= (VersionStrLen + 1);
+    UnicodeStrToAsciiStrS (SerialNumber, OptionalStrStart, OptionalStrSize);
+    OptionalStrStart += (SerialNumberStrLen + 1);
+    OptionalStrSize  -= (SerialNumberStrLen + 1);
+    UnicodeStrToAsciiStrS (AssetTag, OptionalStrStart, OptionalStrSize);
+    OptionalStrStart += (AssetTagStrLen + 1);
+    OptionalStrSize  -= (AssetTagStrLen + 1);
+    UnicodeStrToAsciiStrS (PartNumber, OptionalStrStart, OptionalStrSize);
 
     //
     // Now we have got the full Smbios record, call Smbios protocol to add this record.

+ 6 - 4
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscSystemLanguageStringFunction.c

@@ -1,10 +1,12 @@
 /*++
 
-Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
-                                                                                   

+Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
+                                                                                   
+
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
-                                                                                   

+                                                                                   
+
 
 Module Name:
 
@@ -75,7 +77,7 @@ MISC_SMBIOS_TABLE_FUNCTION(SystemLanguageString)
   SmbiosRecord->Flags   = 1;
   SmbiosRecord->CurrentLanguages = 1;
   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-  UnicodeStrToAsciiStr(Str, OptionalStrStart);
+  UnicodeStrToAsciiStrS (Str, OptionalStrStart, StrLeng + 1 + 1);
 
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.

+ 21 - 10
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscSystemManufacturerFunction.c

@@ -1,6 +1,6 @@
 /*++
 
-Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -47,6 +47,7 @@ AddSmbiosManuCallback (
 {
 
   CHAR8                             *OptionalStrStart;
+  UINTN                             OptionalStrSize;
   UINTN                             ManuStrLen;
   UINTN                             VerStrLen;
   UINTN                             PdNameStrLen;
@@ -245,8 +246,9 @@ AddSmbiosManuCallback (
   //
   // Two zeros following the last string.
   //
-  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE1) + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + SkuNumberStrLen + 1 + FamilyNameStrLen + 1 + 1);
-  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE1) + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + SkuNumberStrLen + 1 + FamilyNameStrLen + 1 + 1);
+  OptionalStrSize = ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + SkuNumberStrLen + 1 + FamilyNameStrLen + 1 + 1;
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE1) + OptionalStrSize);
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE1) + OptionalStrSize);
 
   SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_INFORMATION;
   SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE1);
@@ -290,13 +292,22 @@ AddSmbiosManuCallback (
   SmbiosRecord->WakeUpType = (UINT8)ForType1InputData->SystemWakeupType;
 
   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-  UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);
-  UnicodeStrToAsciiStr(ProductName, OptionalStrStart + ManuStrLen + 1);
-  UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1 + PdNameStrLen + 1);
-  UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1);
-
-  UnicodeStrToAsciiStr(SkuNumber, OptionalStrStart + ManuStrLen + 1 + PdNameStrLen + 1 +  VerStrLen + 1 + SerialNumStrLen + 1);
-  UnicodeStrToAsciiStr(FamilyName, OptionalStrStart + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + SkuNumberStrLen +1);
+  UnicodeStrToAsciiStrS (Manufacturer, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (ManuStrLen + 1);
+  OptionalStrSize  -= (ManuStrLen + 1);
+  UnicodeStrToAsciiStrS (ProductName, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (PdNameStrLen + 1);
+  OptionalStrSize  -= (PdNameStrLen + 1);
+  UnicodeStrToAsciiStrS (Version, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (VerStrLen + 1);
+  OptionalStrSize  -= (VerStrLen + 1);
+  UnicodeStrToAsciiStrS (SerialNumber, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (SerialNumStrLen + 1);
+  OptionalStrSize  -= (SerialNumStrLen + 1);
+  UnicodeStrToAsciiStrS (SkuNumber, OptionalStrStart, OptionalStrSize);
+  OptionalStrStart += (SkuNumberStrLen + 1);
+  OptionalStrSize  -= (SkuNumberStrLen + 1);
+  UnicodeStrToAsciiStrS (FamilyName, OptionalStrStart, OptionalStrSize);
 
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.

+ 6 - 4
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscSystemOptionStringFunction.c

@@ -1,10 +1,12 @@
 /*++
 
-Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
-                                                                                   

+Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
+                                                                                   
+
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
-                                                                                   

+                                                                                   
+
 
 
 Module Name:
@@ -75,7 +77,7 @@ MISC_SMBIOS_TABLE_FUNCTION(SystemOptionString)
 
   SmbiosRecord->StringCount = 1;
   OptionalStrStart = (CHAR8*) (SmbiosRecord + 1);
-  UnicodeStrToAsciiStr(OptionString, OptionalStrStart);
+  UnicodeStrToAsciiStrS (OptionString, OptionalStrStart, OptStrLen + 1 + 1);
 
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.

+ 6 - 4
Platform/Intel/Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscSystemSlotDesignationFunction.c

@@ -1,10 +1,12 @@
 /*++
 
-Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
-                                                                                   

+Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
+                                                                                   
+
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
-                                                                                   

+                                                                                   
+
 
 
 Module Name:
@@ -111,7 +113,7 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscSystemSlotDesignation)
   //
   CopyMem ((UINT8 *) &SmbiosRecord->SlotCharacteristics1,(UINT8 *) &ForType9InputData->SlotCharacteristics,2);
   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
-  UnicodeStrToAsciiStr(SlotDesignation, OptionalStrStart);
+  UnicodeStrToAsciiStrS (SlotDesignation, OptionalStrStart, SlotDesignationStrLen + 1 + 1);
   //
   // Now we have got the full smbios record, call smbios protocol to add this record.
   //

+ 2 - 2
Platform/Intel/Vlv2TbltDevicePkg/VlvPlatformInitDxe/IgdOpRegion.c

@@ -1,7 +1,7 @@
 
 /*++
 
-Copyright (c)  2011  - 2019, Intel Corporation. All rights reserved
+Copyright (c)  2011  - 2020, Intel Corporation. All rights reserved
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -499,7 +499,7 @@ SetGOPVersionCallback (
   ZeroMem (GopVersion, sizeof (GopVersion));
   Status = GetGOPDriverVersion(GopVersion);
   if(!EFI_ERROR(Status)) {
-    StrCpy((CHAR16*)&(mIgdOpRegion.OpRegion->Header.GOPV[0]), GopVersion);
+    StrCpyS ((CHAR16*)&(mIgdOpRegion.OpRegion->Header.GOPV[0]), 16, GopVersion);
     return Status;
   }
   return EFI_UNSUPPORTED;