12GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mVarCheckHiiHex[] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
40 while (DataSize != 0) {
42 if (Size > DataSize) {
46 for (Index = 0; Index < Size; Index += 1) {
47 TempByte = Data[Index];
48 Val[Index * 3 + 0] = mVarCheckHiiHex[TempByte >> 4];
49 Val[Index * 3 + 1] = mVarCheckHiiHex[TempByte & 0xF];
50 Val[Index * 3 + 2] = (CHAR8)((Index == 7) ?
'-' :
' ');
51 Str[Index] = (CHAR8)((TempByte <
' ' || TempByte >
'z') ?
'.' : TempByte);
56 DEBUG ((DEBUG_INFO,
"%*a%08X: %-48a *%a*\r\n", Indent,
"", Offset, Val, Str));
89 UINT16 VarOffsetByteLevel;
90 UINT8 StorageWidthByteLevel;
92 if (HiiQuestion->BitFieldStore) {
93 VarOffsetByteLevel = HiiQuestion->VarOffset / 8;
94 TotalBits = HiiQuestion->VarOffset % 8 + HiiQuestion->StorageWidth;
95 StorageWidthByteLevel = (TotalBits % 8 == 0 ? TotalBits / 8 : TotalBits / 8 + 1);
97 VarOffsetByteLevel = HiiQuestion->VarOffset;
98 StorageWidthByteLevel = HiiQuestion->StorageWidth;
101 if (((UINT32)VarOffsetByteLevel + StorageWidthByteLevel) > DataSize) {
102 DEBUG ((DEBUG_INFO,
"VarCheckHiiQuestion fail: (VarOffset(0x%04x) + StorageWidth(0x%02x)) > Size(0x%x)\n", VarOffsetByteLevel, StorageWidthByteLevel, DataSize));
107 CopyMem (&OneData, (UINT8 *)Data + VarOffsetByteLevel, StorageWidthByteLevel);
108 if (HiiQuestion->BitFieldStore) {
112 StartBit = HiiQuestion->VarOffset % 8;
113 EndBit = StartBit + HiiQuestion->StorageWidth - 1;
117 switch (HiiQuestion->OpCode) {
118 case EFI_IFR_ONE_OF_OP:
120 while ((
UINTN)Ptr < (
UINTN)HiiQuestion + HiiQuestion->Length) {
122 if (HiiQuestion->BitFieldStore) {
126 CopyMem (&OneValue, Ptr,
sizeof (UINT32));
128 CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
131 if (OneData == OneValue) {
138 if (HiiQuestion->BitFieldStore) {
139 Ptr +=
sizeof (UINT32);
141 Ptr += HiiQuestion->StorageWidth;
145 if ((
UINTN)Ptr >= ((
UINTN)HiiQuestion + HiiQuestion->Length)) {
149 DEBUG ((DEBUG_INFO,
"VarCheckHiiQuestion fail: OneOf mismatch (0x%lx)\n", OneData));
158 case EFI_IFR_CHECKBOX_OP:
159 if ((OneData != 0) && (OneData != 1)) {
160 DEBUG ((DEBUG_INFO,
"VarCheckHiiQuestion fail: CheckBox mismatch (0x%lx)\n", OneData));
169 case EFI_IFR_NUMERIC_OP:
173 if (HiiQuestion->BitFieldStore) {
177 CopyMem (&Minimum, Ptr,
sizeof (UINT32));
178 Ptr +=
sizeof (UINT32);
179 CopyMem (&Maximum, Ptr,
sizeof (UINT32));
180 Ptr +=
sizeof (UINT32);
182 CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
183 Ptr += HiiQuestion->StorageWidth;
184 CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
185 Ptr += HiiQuestion->StorageWidth;
191 if ((OneData < Minimum) || (OneData > Maximum)) {
192 DEBUG ((DEBUG_INFO,
"VarCheckHiiQuestion fail: Numeric mismatch (0x%lx)\n", OneData));
201 case EFI_IFR_ORDERED_LIST_OP:
203 if (((UINT32)HiiQuestion->VarOffset + HiiQuestion->StorageWidth * MaxContainers) > DataSize) {
204 DEBUG ((DEBUG_INFO,
"VarCheckHiiQuestion fail: (VarOffset(0x%04x) + StorageWidth(0x%02x) * MaxContainers(0x%02x)) > Size(0x%x)\n", HiiQuestion->VarOffset, HiiQuestion->StorageWidth, MaxContainers, DataSize));
208 for (Index = 0; Index < MaxContainers; Index++) {
210 CopyMem (&OneData, (UINT8 *)Data + HiiQuestion->VarOffset + HiiQuestion->StorageWidth * Index, HiiQuestion->StorageWidth);
219 while ((
UINTN)Ptr < ((
UINTN)HiiQuestion + HiiQuestion->Length)) {
221 CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
222 if (OneData == OneValue) {
229 Ptr += HiiQuestion->StorageWidth;
232 if ((
UINTN)Ptr >= ((
UINTN)HiiQuestion + HiiQuestion->Length)) {
236 DEBUG ((DEBUG_INFO,
"VarCheckHiiQuestion fail: OrderedList mismatch\n"));
274 IN CHAR16 *VariableName,
276 IN UINT32 Attributes,
284 if (HiiVariableBin ==
NULL) {
288 if ((((Attributes & EFI_VARIABLE_APPEND_WRITE) == 0) && (DataSize == 0)) || (Attributes == 0)) {
298 while ((
UINTN)HiiVariable < ((
UINTN)HiiVariableBin + HiiVariableBinSize)) {
299 if ((
StrCmp ((CHAR16 *)(HiiVariable + 1), VariableName) == 0) &&
305 DEBUG ((DEBUG_INFO,
"VarCheckHiiVariable - %s:%g with Attributes = 0x%08x Size = 0x%x\n", VariableName, VendorGuid, Attributes, DataSize));
306 if (HiiVariable->Attributes != Attributes) {
307 DEBUG ((DEBUG_INFO,
"VarCheckHiiVariable fail for Attributes - 0x%08x\n", HiiVariable->Attributes));
308 return EFI_SECURITY_VIOLATION;
312 DEBUG ((DEBUG_INFO,
"VarCheckHiiVariable - CHECK PASS with DataSize == 0 !\n"));
316 if (HiiVariable->Size != DataSize) {
317 DEBUG ((DEBUG_INFO,
"VarCheckHiiVariable fail for Size - 0x%x\n", HiiVariable->Size));
318 return EFI_SECURITY_VIOLATION;
326 while ((
UINTN)HiiQuestion < ((
UINTN)HiiVariable + HiiVariable->Length)) {
328 return EFI_SECURITY_VIOLATION;
337 DEBUG ((DEBUG_INFO,
"VarCheckHiiVariable - ALL CHECK PASS!\n"));
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
UINT64 EFIAPI BitFieldRead64(IN UINT64 Operand, IN UINTN StartBit, IN UINTN EndBit)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
#define GLOBAL_REMOVE_IF_UNREFERENCED
#define DEBUG(Expression)
#define DEBUG_CODE(Expression)
EFI_STATUS EFIAPI CheckHiiVariableCommon(IN VAR_CHECK_HII_VARIABLE_HEADER *HiiVariableBin, IN UINTN HiiVariableBinSize, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
BOOLEAN VarCheckHiiQuestion(IN VAR_CHECK_HII_QUESTION_HEADER *HiiQuestion, IN VOID *Data, IN UINTN DataSize)
VOID VarCheckHiiInternalDumpHex(IN UINTN Indent, IN UINTN Offset, IN UINTN DataSize, IN VOID *UserData)