]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Nt32Pkg: Fix code to correctly set SMBIOS Type 2 Length
authorChris Phillips <chrisp@hpe.com>
Tue, 10 Jan 2017 16:48:45 +0000 (00:48 +0800)
committerStar Zeng <star.zeng@intel.com>
Thu, 12 Jan 2017 08:46:27 +0000 (16:46 +0800)
When running Nt32Pkg, SMBIOS Type 2 had the wrong Length.
Fixed the code to use the correct structure in sizeof, and properly account for ContainedObjectHandles.
Also updated variable names with Assert -> Asset

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chris Phillips <chrisp@hpe.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Nt32Pkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerFunction.c

index 303726c3fd5927cd55e52ef596e77165231aead0..765627a8e6222a530f0ccae4aa8de2335532895d 100644 (file)
@@ -3,6 +3,7 @@
   SMBIOS type 2.\r
   \r
 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2017 Hewlett Packard Enterprise Development LP<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
@@ -31,7 +32,7 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
   UINTN                           ManuStrLen;\r
   UINTN                           ProductStrLen;\r
   UINTN                           VerStrLen;\r
-  UINTN                           AssertTagStrLen;\r
+  UINTN                           AssetTagStrLen;\r
   UINTN                           SerialNumStrLen;\r
   UINTN                           ChassisStrLen;\r
   EFI_STATUS                      Status;\r
@@ -39,7 +40,7 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
   EFI_STRING                      Product;\r
   EFI_STRING                      Version;\r
   EFI_STRING                      SerialNumber;\r
-  EFI_STRING                      AssertTag;\r
+  EFI_STRING                      AssetTag;\r
   EFI_STRING                      Chassis;\r
   STRING_REF                      TokenToGet;\r
   EFI_SMBIOS_HANDLE               SmbiosHandle;\r
@@ -84,9 +85,9 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
   }\r
 \r
   TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG);\r
-  AssertTag = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
-  AssertTagStrLen = StrLen(AssertTag);\r
-  if (AssertTagStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+  AssetTag = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  AssetTagStrLen = StrLen(AssetTag);\r
+  if (AssetTagStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -101,11 +102,16 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
   //\r
   // Two zeros following the last string.\r
   //\r
-  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1);\r
-  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1);\r
+  // Since we fill NumberOfContainedObjectHandles = 0, remove sizeof (UINT16) bytes for ContainedObjectHandles[1]\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE2) - sizeof (UINT16) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssetTagStrLen + 1 + ChassisStrLen + 1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE2) - sizeof (UINT16) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssetTagStrLen + 1 + ChassisStrLen + 1 + 1);\r
 \r
   SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION;\r
-  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE2);\r
+  //\r
+  // Since we fill NumberOfContainedObjectHandles = 0, remove sizeof (UINT16) bytes for ContainedObjectHandles[1]\r
+  //\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE2) - sizeof (UINT16);\r
   //\r
   // Make handle chosen by smbios protocol.add automatically.\r
   //\r
@@ -127,7 +133,7 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
   //\r
   SmbiosRecord->SerialNumber = 4;  \r
   //\r
-  // AssertTag will be the 5th optional string following the formatted structure.\r
+  // AssetTag will be the 5th optional string following the formatted structure.\r
   //\r
   SmbiosRecord->AssetTag = 5;  \r
 \r
@@ -142,15 +148,15 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
   \r
   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
   //\r
-  // Since we fill NumberOfContainedObjectHandles = 0 for simple, just after this filed to fill string\r
+  // Since we fill NumberOfContainedObjectHandles = 0, just after this field to fill string\r
   //\r
-  OptionalStrStart -= 2;\r
+  OptionalStrStart -= sizeof (UINT16);\r
   UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);\r
   UnicodeStrToAsciiStr(Product, OptionalStrStart + ManuStrLen + 1);\r
   UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1);\r
   UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1);\r
-  UnicodeStrToAsciiStr(AssertTag, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);\r
-  UnicodeStrToAsciiStr(Chassis, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1);\r
+  UnicodeStrToAsciiStr(AssetTag, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);\r
+  UnicodeStrToAsciiStr(Chassis, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssetTagStrLen + 1);\r
   //\r
   // Now we have got the full smbios record, call smbios protocol to add this record.\r
   //\r