From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ml01.01.org (Postfix) with ESMTP id 2EB3F1A1E1F for ; Tue, 9 Aug 2016 20:13:44 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 09 Aug 2016 20:13:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,497,1464678000"; d="scan'208";a="1022771240" Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.135]) by fmsmga001.fm.intel.com with ESMTP; 09 Aug 2016 20:13:42 -0700 From: Dandan Bi To: edk2-devel@lists.01.org Cc: Liming Gao , Eric Dong Date: Wed, 10 Aug 2016 11:13:13 +0800 Message-Id: <1470798793-83436-1-git-send-email-dandan.bi@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [patch] MdeModulePkg/Browser: Enhance the logic when getting value from AltResp X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Aug 2016 03:13:44 -0000 This patch is to enhance SetupBrowser to handle following two cases: 1. When searching BlockName in AltResp, the hex digits of related BlockName in AltResp may be in uppercase. 2. When converting the Value in AltResp to HiiValue, the length of value string is bigger than the length of StorageWidth of the question. Cc: Liming Gao Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Dandan Bi Reviewed-by: Eric Dong --- MdeModulePkg/Universal/SetupBrowserDxe/Setup.c | 54 +++++++++++++------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c index 6b38547..69fc41f 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c @@ -1427,44 +1427,41 @@ BufferToValue ( } TempChar = *StringPtr; *StringPtr = L'\0'; LengthStr = StrLen (Value); + + if (LengthStr > (UINTN) Question->StorageWidth * 2) { + Length = (UINTN) Question->StorageWidth * 2; + } else { + Length = LengthStr; + } Status = EFI_SUCCESS; if (!IsBufferStorage && IsString) { // // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD" // Add string tail char L'\0' into Length // - Length = Question->StorageWidth + sizeof (CHAR16); - if (Length < ((LengthStr / 4 + 1) * 2)) { - Status = EFI_BUFFER_TOO_SMALL; - } else { - DstBuf = (CHAR16 *) Dst; - ZeroMem (TemStr, sizeof (TemStr)); - for (Index = 0; Index < LengthStr; Index += 4) { - StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), Value + Index, 4); - DstBuf[Index/4] = (CHAR16) StrHexToUint64 (TemStr); - } - // - // Add tailing L'\0' character - // - DstBuf[Index/4] = L'\0'; + DstBuf = (CHAR16 *) Dst; + ZeroMem (TemStr, sizeof (TemStr)); + for (Index = 0; Index < Length; Index += 4) { + StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), Value + Index, 4); + DstBuf[Index/4] = (CHAR16) StrHexToUint64 (TemStr); } + // + // Add tailing L'\0' character + // + DstBuf[Index/4] = L'\0'; } else { - if (Question->StorageWidth < ((LengthStr + 1) / 2)) { - Status = EFI_BUFFER_TOO_SMALL; - } else { - ZeroMem (TemStr, sizeof (TemStr)); - for (Index = 0; Index < LengthStr; Index ++) { - TemStr[0] = Value[LengthStr - Index - 1]; - DigitUint8 = (UINT8) StrHexToUint64 (TemStr); - if ((Index & 1) == 0) { - Dst [Index/2] = DigitUint8; - } else { - Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]); - } + ZeroMem (TemStr, sizeof (TemStr)); + for (Index = 0; Index < Length; Index ++) { + TemStr[0] = Value[LengthStr - Index - 1]; + DigitUint8 = (UINT8) StrHexToUint64 (TemStr); + if ((Index & 1) == 0) { + Dst [Index/2] = DigitUint8; + } else { + Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]); } } } *StringPtr = TempChar; @@ -3755,10 +3752,15 @@ GetOffsetFromConfigResp ( // // Type is EFI_HII_VARSTORE_EFI_VARIABLE or EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER // // + // Convert all hex digits in ConfigResp to lower case before searching. + // + HiiToLower (ConfigResp); + + // // 1. Directly use Question->BlockName to find. // RequestElement = StrStr (ConfigResp, Question->BlockName); if (RequestElement != NULL) { // -- 1.9.5.msysgit.1