From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F06D921CEB11B for ; Mon, 11 Sep 2017 20:41:51 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2017 20:44:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,381,1500966000"; d="scan'208";a="134300897" Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.135]) by orsmga002.jf.intel.com with ESMTP; 11 Sep 2017 20:44:47 -0700 From: Dandan Bi To: edk2-devel@lists.01.org Cc: Eric Dong , Liming Gao Date: Tue, 12 Sep 2017 11:44:05 +0800 Message-Id: <1505187848-389908-4-git-send-email-dandan.bi@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1505187848-389908-1-git-send-email-dandan.bi@intel.com> References: <1505187848-389908-1-git-send-email-dandan.bi@intel.com> Subject: [PATCH v2 3/6] MdeModulePkg/UefiHiiLib: Add codes to validate question with bit fields X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Sep 2017 03:41:52 -0000 V2: Add previous missing logic to handle question with Bit VarStore in UefiHiiLib. REF:https://bugzilla.tianocore.org/show_bug.cgi?id=545 In UefiHiiLib, there are codes to validate the current setting of questions, now update the logic to handle question with bit storage. Cc: Eric Dong Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Dandan Bi --- MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 270 ++++++++++++++++------- MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h | 4 +- MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf | 5 +- 3 files changed, 202 insertions(+), 77 deletions(-) diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index cd0cd35..9df42d1 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -49,10 +49,11 @@ EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL; GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList = { sizeof (EFI_HII_PACKAGE_HEADER), EFI_HII_PACKAGE_END }; +BOOLEAN mQuestionReferBitField = FALSE; /** Extract Hii package list GUID for given HII handle. If HiiHandle could not be found in the HII database, then ASSERT. If Guid is NULL, then ASSERT. @@ -1167,10 +1168,16 @@ ValidateQuestionFromVfr ( EFI_IFR_STRING *IfrString; CHAR8 *VarStoreName; UINTN Index; CHAR16 *QuestionName; CHAR16 *StringPtr; + UINT16 BitOffset; + UINT16 BitWidth; + UINT16 TotalBits; + UINT32 PreBits; + UINT32 Mask; + UINT32 *Value; // // Initialize the local variables. // Index = 0; @@ -1180,10 +1187,12 @@ ValidateQuestionFromVfr ( IfrVarStore = NULL; IfrNameValueStore = NULL; IfrEfiVarStore = NULL; ZeroMem (&VarStoreData, sizeof (IFR_VARSTORAGE_DATA)); ZeroMem (&VarBlockData, sizeof (VarBlockData)); + BitOffset = 0; + BitWidth = 0; // // Check IFR value is in block data, then Validate Value // PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); @@ -1343,12 +1352,23 @@ ValidateQuestionFromVfr ( } } else { // // Get Offset by Question header and Width by DataType Flags // - Offset = IfrOneOf->Question.VarStoreInfo.VarOffset; - Width = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE)); + if (mQuestionReferBitField) { + // + // Get the byte offset/width for bit field. + // + BitOffset = IfrOneOf->Question.VarStoreInfo.VarOffset; + BitWidth = IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE_BIT; + Offset = BitOffset / 8; + TotalBits = BitOffset - (Offset * 8) + BitWidth; + Width = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1); + } else { + Offset = IfrOneOf->Question.VarStoreInfo.VarOffset; + Width = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE)); + } // // Check whether this question is in current block array. // if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { // @@ -1368,11 +1388,27 @@ ValidateQuestionFromVfr ( // // Get the current value for oneof opcode // VarValue = 0; - CopyMem (&VarValue, VarBuffer + Offset, Width); + if (mQuestionReferBitField) { + // + // Get the value in bit fields. + // + mQuestionReferBitField = FALSE; + Value = (UINT32*) &VarValue; + PreBits = BitOffset - Offset * 8; + Mask = (1 << BitWidth) -1; + *Value = *(VarBuffer + Offset); + *Value |= *(VarBuffer + Offset + 1) << 8; + *Value |= *(VarBuffer + Offset + 2) << 16; + *Value |= *(VarBuffer + Offset + 3) << 24; + *Value >>= PreBits; + *Value &= Mask; + } else { + CopyMem (&VarValue, VarBuffer + Offset, Width); + } } // // Set Block Data, to be checked in the following Oneof option opcode. // VarBlockData.OpCode = IfrOpHdr->OpCode; @@ -1414,12 +1450,26 @@ ValidateQuestionFromVfr ( } } else { // // Get Offset by Question header and Width by DataType Flags // - Offset = IfrNumeric->Question.VarStoreInfo.VarOffset; - Width = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE)); + if (mQuestionReferBitField) { + // + // Get the byte offset/width for bit field. + // + BitOffset = IfrNumeric->Question.VarStoreInfo.VarOffset; + BitWidth = IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE_BIT; + Offset = BitOffset / 8; + // + // Use current bit width and the bit width before current bit (with same byte offset) to calculate the byte width. + // + TotalBits = BitOffset - (Offset * 8) + BitWidth; + Width = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1); + } else { + Offset = IfrNumeric->Question.VarStoreInfo.VarOffset; + Width = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE)); + } // // Check whether this question is in current block array. // if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { // @@ -1439,81 +1489,118 @@ ValidateQuestionFromVfr ( // // Check the current value is in the numeric range. // VarValue = 0; - CopyMem (&VarValue, VarBuffer + Offset, Width); - } - if ((IfrNumeric->Flags & EFI_IFR_DISPLAY) == 0) { - switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) { - case EFI_IFR_NUMERIC_SIZE_1: - if ((INT8) VarValue < (INT8) IfrNumeric->data.u8.MinValue || (INT8) VarValue > (INT8) IfrNumeric->data.u8.MaxValue) { - // - // Not in the valid range. - // - return EFI_INVALID_PARAMETER; - } - break; - case EFI_IFR_NUMERIC_SIZE_2: - if ((INT16) VarValue < (INT16) IfrNumeric->data.u16.MinValue || (INT16) VarValue > (INT16) IfrNumeric->data.u16.MaxValue) { - // - // Not in the valid range. - // - return EFI_INVALID_PARAMETER; - } - break; - case EFI_IFR_NUMERIC_SIZE_4: - if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) { - // - // Not in the valid range. - // - return EFI_INVALID_PARAMETER; - } - break; - case EFI_IFR_NUMERIC_SIZE_8: - if ((INT64) VarValue < (INT64) IfrNumeric->data.u64.MinValue || (INT64) VarValue > (INT64) IfrNumeric->data.u64.MaxValue) { - // - // Not in the valid range. - // - return EFI_INVALID_PARAMETER; - } - break; + if (mQuestionReferBitField) { + // + // Get the value in the bit fields. + // + Value = (UINT32*) &VarValue; + PreBits = BitOffset - Offset * 8; + Mask = (1<< BitWidth) -1; + *Value = *(VarBuffer + Offset); + *Value |= *(VarBuffer + Offset + 1) << 8; + *Value |= *(VarBuffer + Offset + 2) << 16; + *Value |= *(VarBuffer + Offset + 3) << 24; + *Value >>= PreBits; + *Value &= Mask; + } else { + CopyMem (&VarValue, VarBuffer + Offset, Width); } + } + if ( mQuestionReferBitField) { + // + // Value in bit fields was stored as UINt32 type. + // + mQuestionReferBitField = FALSE; + if ((IfrNumeric->Flags & EFI_IFR_DISPLAY_BIT) == 0) { + if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + } else { + if (VarValue < IfrNumeric->data.u32.MinValue || VarValue > IfrNumeric->data.u32.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + } } else { - switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) { - case EFI_IFR_NUMERIC_SIZE_1: - if ((UINT8) VarValue < IfrNumeric->data.u8.MinValue || (UINT8) VarValue > IfrNumeric->data.u8.MaxValue) { - // - // Not in the valid range. - // - return EFI_INVALID_PARAMETER; - } - break; - case EFI_IFR_NUMERIC_SIZE_2: - if ((UINT16) VarValue < IfrNumeric->data.u16.MinValue || (UINT16) VarValue > IfrNumeric->data.u16.MaxValue) { - // - // Not in the valid range. - // - return EFI_INVALID_PARAMETER; - } - break; - case EFI_IFR_NUMERIC_SIZE_4: - if ((UINT32) VarValue < IfrNumeric->data.u32.MinValue || (UINT32) VarValue > IfrNumeric->data.u32.MaxValue) { - // - // Not in the valid range. - // - return EFI_INVALID_PARAMETER; + if ((IfrNumeric->Flags & EFI_IFR_DISPLAY) == 0) { + switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) { + case EFI_IFR_NUMERIC_SIZE_1: + if ((INT8) VarValue < (INT8) IfrNumeric->data.u8.MinValue || (INT8) VarValue > (INT8) IfrNumeric->data.u8.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; + case EFI_IFR_NUMERIC_SIZE_2: + if ((INT16) VarValue < (INT16) IfrNumeric->data.u16.MinValue || (INT16) VarValue > (INT16) IfrNumeric->data.u16.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; + case EFI_IFR_NUMERIC_SIZE_4: + if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; + case EFI_IFR_NUMERIC_SIZE_8: + if ((INT64) VarValue < (INT64) IfrNumeric->data.u64.MinValue || (INT64) VarValue > (INT64) IfrNumeric->data.u64.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; } - break; - case EFI_IFR_NUMERIC_SIZE_8: - if ((UINT64) VarValue < IfrNumeric->data.u64.MinValue || (UINT64) VarValue > IfrNumeric->data.u64.MaxValue) { - // - // Not in the valid range. - // - return EFI_INVALID_PARAMETER; + } else { + switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) { + case EFI_IFR_NUMERIC_SIZE_1: + if ((UINT8) VarValue < IfrNumeric->data.u8.MinValue || (UINT8) VarValue > IfrNumeric->data.u8.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; + case EFI_IFR_NUMERIC_SIZE_2: + if ((UINT16) VarValue < IfrNumeric->data.u16.MinValue || (UINT16) VarValue > IfrNumeric->data.u16.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; + case EFI_IFR_NUMERIC_SIZE_4: + if ((UINT32) VarValue < IfrNumeric->data.u32.MinValue || (UINT32) VarValue > IfrNumeric->data.u32.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; + case EFI_IFR_NUMERIC_SIZE_8: + if ((UINT64) VarValue < IfrNumeric->data.u64.MinValue || (UINT64) VarValue > IfrNumeric->data.u64.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; } - break; } } break; case EFI_IFR_CHECKBOX_OP: // @@ -1552,12 +1639,23 @@ ValidateQuestionFromVfr ( } } else { // // Get Offset by Question header // - Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset; - Width = (UINT16) sizeof (BOOLEAN); + if (mQuestionReferBitField) { + // + // Get the byte offset/width for bit field. + // + BitOffset = IfrCheckBox->Question.VarStoreInfo.VarOffset; + BitWidth = 1; + Offset = BitOffset / 8; + TotalBits = BitOffset - (Offset * 8) + BitWidth; + Width = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1); + } else { + Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset; + Width = (UINT16) sizeof (BOOLEAN); + } // // Check whether this question is in current block array. // if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { // @@ -1576,11 +1674,27 @@ ValidateQuestionFromVfr ( } // // Check the current value is in the numeric range. // VarValue = 0; - CopyMem (&VarValue, VarBuffer + Offset, Width); + if (mQuestionReferBitField) { + // + // Get the value in bit fields. + // + mQuestionReferBitField = FALSE; + Value = (UINT32*) &VarValue; + PreBits = BitOffset - Offset* 8; + Mask = (1<< BitWidth) -1; + *Value = *(VarBuffer + Offset); + *Value |= *(VarBuffer + Offset + 1) << 8; + *Value |= *(VarBuffer + Offset + 2) << 16; + *Value |= *(VarBuffer + Offset + 3) << 24; + *Value >>= PreBits; + *Value &= Mask; + } else { + CopyMem (&VarValue, VarBuffer + Offset, Width); + } } // // Boolean type, only 1 and 0 is valid. // if (VarValue > 1) { @@ -1692,10 +1806,11 @@ ValidateQuestionFromVfr ( VarBlockData.OpCode = 0; } } break; case EFI_IFR_END_OP: + mQuestionReferBitField = FALSE; // // Decrease opcode scope for the validated opcode // if (VarBlockData.Scope > 0) { VarBlockData.Scope --; @@ -1706,10 +1821,15 @@ ValidateQuestionFromVfr ( // if ((VarBlockData.Scope == 0) && (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP)) { return EFI_INVALID_PARAMETER; } break; + case EFI_IFR_GUID_OP: + if (CompareGuid ((EFI_GUID *)((UINT8*)IfrOpHdr + sizeof (EFI_IFR_OP_HEADER)), &gEfiIfrBitvarstoreGuid)) { + mQuestionReferBitField = TRUE; + } + break; default: // // Increase Scope for the validated opcode // if (VarBlockData.Scope > 0) { diff --git a/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h b/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h index 9bf7696..293c226 100644 --- a/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h +++ b/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h @@ -1,9 +1,9 @@ /** @file Internal include file for the HII Library instance. - Copyright (c) 2007, Intel Corporation. All rights reserved.
+ Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -18,10 +18,12 @@ #include #include #include +#include + #include #include #include #include #include diff --git a/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf b/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf index 62f435a..411c758 100644 --- a/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf +++ b/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf @@ -1,9 +1,9 @@ ## @file # HII Library implementation using UEFI HII protocols and services. # -# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at # http://opensource.org/licenses/bsd-license.php @@ -49,5 +49,8 @@ PrintLib [Protocols] gEfiFormBrowser2ProtocolGuid ## SOMETIMES_CONSUMES gEfiDevicePathProtocolGuid ## SOMETIMES_CONSUMES + +[Guids] + gEfiIfrBitvarstoreGuid ## SOMETIMES_CONSUMES ## GUID -- 1.9.5.msysgit.1