]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerFunction.c
MdeModulePkg: Fix use-after-free error in InstallConfigurationTable()
[mirror_edk2.git] / Nt32Pkg / MiscSubClassPlatformDxe / MiscBaseBoardManufacturerFunction.c
1 /** @file
2 BaseBoard manufacturer information boot time changes.
3 SMBIOS type 2.
4
5 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
6 (C) Copyright 2017 Hewlett Packard Enterprise Development LP<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include "MiscSubclassDriver.h"
18 /**
19 This function makes boot time changes to the contents of the
20 MiscBaseBoardManufacturer (Type 2).
21
22 @param RecordData Pointer to copy of RecordData from the Data Table.
23
24 @retval EFI_SUCCESS All parameters were valid.
25 @retval EFI_UNSUPPORTED Unexpected RecordType value.
26 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
27
28 **/
29 MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
30 {
31 CHAR8 *OptionalStrStart;
32 UINTN ManuStrLen;
33 UINTN ProductStrLen;
34 UINTN VerStrLen;
35 UINTN AssetTagStrLen;
36 UINTN SerialNumStrLen;
37 UINTN ChassisStrLen;
38 EFI_STATUS Status;
39 EFI_STRING Manufacturer;
40 EFI_STRING Product;
41 EFI_STRING Version;
42 EFI_STRING SerialNumber;
43 EFI_STRING AssetTag;
44 EFI_STRING Chassis;
45 STRING_REF TokenToGet;
46 EFI_SMBIOS_HANDLE SmbiosHandle;
47 SMBIOS_TABLE_TYPE2 *SmbiosRecord;
48 EFI_MISC_BASE_BOARD_MANUFACTURER *ForType2InputData;
49
50 ForType2InputData = (EFI_MISC_BASE_BOARD_MANUFACTURER *)RecordData;
51
52 //
53 // First check for invalid parameters.
54 //
55 if (RecordData == NULL) {
56 return EFI_INVALID_PARAMETER;
57 }
58
59 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER);
60 Manufacturer = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
61 ManuStrLen = StrLen(Manufacturer);
62 if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {
63 return EFI_UNSUPPORTED;
64 }
65
66 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME);
67 Product = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
68 ProductStrLen = StrLen(Product);
69 if (ProductStrLen > SMBIOS_STRING_MAX_LENGTH) {
70 return EFI_UNSUPPORTED;
71 }
72
73 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION);
74 Version = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
75 VerStrLen = StrLen(Version);
76 if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
77 return EFI_UNSUPPORTED;
78 }
79
80 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_SERIAL_NUMBER);
81 SerialNumber = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
82 SerialNumStrLen = StrLen(SerialNumber);
83 if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {
84 return EFI_UNSUPPORTED;
85 }
86
87 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG);
88 AssetTag = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
89 AssetTagStrLen = StrLen(AssetTag);
90 if (AssetTagStrLen > SMBIOS_STRING_MAX_LENGTH) {
91 return EFI_UNSUPPORTED;
92 }
93
94 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_CHASSIS_LOCATION);
95 Chassis = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
96 ChassisStrLen = StrLen(Chassis);
97 if (ChassisStrLen > SMBIOS_STRING_MAX_LENGTH) {
98 return EFI_UNSUPPORTED;
99 }
100
101
102 //
103 // Two zeros following the last string.
104 //
105 // Since we fill NumberOfContainedObjectHandles = 0, remove sizeof (UINT16) bytes for ContainedObjectHandles[1]
106 //
107 SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE2) - sizeof (UINT16) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssetTagStrLen + 1 + ChassisStrLen + 1 + 1);
108 ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE2) - sizeof (UINT16) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssetTagStrLen + 1 + ChassisStrLen + 1 + 1);
109
110 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION;
111 //
112 // Since we fill NumberOfContainedObjectHandles = 0, remove sizeof (UINT16) bytes for ContainedObjectHandles[1]
113 //
114 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE2) - sizeof (UINT16);
115 //
116 // Make handle chosen by smbios protocol.add automatically.
117 //
118 SmbiosRecord->Hdr.Handle = 0;
119 //
120 // Manu will be the 1st optional string following the formatted structure.
121 //
122 SmbiosRecord->Manufacturer = 1;
123 //
124 // ProductName will be the 2st optional string following the formatted structure.
125 //
126 SmbiosRecord->ProductName = 2;
127 //
128 // Version will be the 3rd optional string following the formatted structure.
129 //
130 SmbiosRecord->Version = 3;
131 //
132 // SerialNumber will be the 4th optional string following the formatted structure.
133 //
134 SmbiosRecord->SerialNumber = 4;
135 //
136 // AssetTag will be the 5th optional string following the formatted structure.
137 //
138 SmbiosRecord->AssetTag = 5;
139
140 //
141 // LocationInChassis will be the 6th optional string following the formatted structure.
142 //
143 SmbiosRecord->LocationInChassis = 6;
144 SmbiosRecord->FeatureFlag = (*(BASE_BOARD_FEATURE_FLAGS*)&(ForType2InputData->BaseBoardFeatureFlags));
145 SmbiosRecord->ChassisHandle = 0;
146 SmbiosRecord->BoardType = (UINT8)ForType2InputData->BaseBoardType;
147 SmbiosRecord->NumberOfContainedObjectHandles = 0;
148
149 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
150 //
151 // Since we fill NumberOfContainedObjectHandles = 0, just after this field to fill string
152 //
153 OptionalStrStart -= sizeof (UINT16);
154 UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);
155 UnicodeStrToAsciiStr(Product, OptionalStrStart + ManuStrLen + 1);
156 UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1);
157 UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1);
158 UnicodeStrToAsciiStr(AssetTag, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);
159 UnicodeStrToAsciiStr(Chassis, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssetTagStrLen + 1);
160 //
161 // Now we have got the full smbios record, call smbios protocol to add this record.
162 //
163 Status = AddSmbiosRecord (Smbios, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord);
164
165 FreePool(SmbiosRecord);
166 return Status;
167 }