]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Expression.c
MdeModulePkg/SetupBrowserDxe: ASSERT GetBufferForValue(&Value)
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Expression.c
index 1077b06669adbbb7d94319649560f89ba8d9eb36..d273d2aac3d023381ba1fac8d5c9d0028cfeca68 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
 Utility functions for expression evaluation.\r
 \r
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -157,7 +151,7 @@ PushStack (
     (*StackPtr)->Buffer = AllocateCopyPool(Data->BufferLen, Data->Buffer);\r
     ASSERT ((*StackPtr)->Buffer != NULL);\r
   }\r
-  \r
+\r
   *StackPtr = *StackPtr + 1;\r
 \r
   return EFI_SUCCESS;\r
@@ -210,7 +204,7 @@ ResetCurrentExpressionStack (
   mCurrentExpressionPointer   = mCurrentExpressionStack;\r
   mFormExpressionPointer      = mFormExpressionStack;\r
   mStatementExpressionPointer = mStatementExpressionStack;\r
-  mOptionExpressionPointer    = mOptionExpressionStack;  \r
+  mOptionExpressionPointer    = mOptionExpressionStack;\r
 }\r
 \r
 \r
@@ -293,7 +287,7 @@ ResetMapExpressionListStack (
                                  pointer\r
   @param  StackEnd               On input: old stack end; On output: new stack end\r
   @param  MemberSize             The stack member size.\r
-  \r
+\r
   @retval EFI_SUCCESS            Grow stack success.\r
   @retval EFI_OUT_OF_RESOURCES   No enough memory for stack space.\r
 \r
@@ -383,7 +377,7 @@ PushConditionalStack (
   //\r
   // Push the item onto the stack\r
   //\r
-  CopyMem (*StackPtr, Data, sizeof (FORM_EXPRESSION *)); \r
+  CopyMem (*StackPtr, Data, sizeof (FORM_EXPRESSION *));\r
   *StackPtr = *StackPtr + 1;\r
 \r
   return EFI_SUCCESS;\r
@@ -426,15 +420,15 @@ PopConditionalStack (
 \r
 /**\r
   Get the expression list count.\r
-  \r
-  @param  Level                  Which type this expression belong to. Form, \r
+\r
+  @param  Level                  Which type this expression belong to. Form,\r
                                  statement or option?\r
 \r
   @retval >=0                    The expression count\r
   @retval -1                     Input parameter error.\r
 \r
 **/\r
-INTN \r
+INTN\r
 GetConditionalExpressionCount (\r
   IN EXPRESS_LEVEL       Level\r
   )\r
@@ -449,13 +443,13 @@ GetConditionalExpressionCount (
     default:\r
       ASSERT (FALSE);\r
       return -1;\r
-  } \r
+  }\r
 }\r
 \r
 /**\r
   Get the expression Buffer pointer.\r
-  \r
-  @param  Level                  Which type this expression belong to. Form, \r
+\r
+  @param  Level                  Which type this expression belong to. Form,\r
                                  statement or option?\r
 \r
   @retval  The start pointer of the expression buffer or NULL.\r
@@ -476,7 +470,7 @@ GetConditionalExpressionList (
     default:\r
       ASSERT (FALSE);\r
       return NULL;\r
-  } \r
+  }\r
 }\r
 \r
 \r
@@ -484,7 +478,7 @@ GetConditionalExpressionList (
   Push the expression options onto the Stack.\r
 \r
   @param  Pointer                Pointer to the current expression.\r
-  @param  Level                  Which type this expression belong to. Form, \r
+  @param  Level                  Which type this expression belong to. Form,\r
                                  statement or option?\r
 \r
   @retval EFI_SUCCESS            The value was pushed onto the stack.\r
@@ -528,7 +522,7 @@ PushConditionalExpression (
 /**\r
   Pop the expression options from the Stack\r
 \r
-  @param  Level                  Which type this expression belong to. Form, \r
+  @param  Level                  Which type this expression belong to. Form,\r
                                  statement or option?\r
 \r
   @retval EFI_SUCCESS            The value was pushed onto the stack.\r
@@ -751,6 +745,7 @@ PopExpression (
 **/\r
 UINTN\r
 SaveExpressionEvaluationStackOffset (\r
+  VOID\r
   )\r
 {\r
   UINTN TempStackOffset;\r
@@ -991,7 +986,7 @@ IfrStrToUpper (
 /**\r
   Check whether this value type can be transfer to EFI_IFR_TYPE_BUFFER type.\r
 \r
-  EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to \r
+  EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to\r
   EFI_IFR_TYPE_BUFFER when do the value compare.\r
 \r
   @param  Value                  Expression value to compare on.\r
@@ -1047,11 +1042,11 @@ IsTypeInUINT64 (
 /**\r
   Return the buffer length for this value.\r
 \r
-  EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to \r
+  EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to\r
   EFI_IFR_TYPE_BUFFER when do the value compare.\r
 \r
   @param   Value                  Expression value to compare on.\r
-  \r
+\r
   @retval  BufLen                 Return the buffer length.\r
 \r
 **/\r
@@ -1081,7 +1076,7 @@ GetLengthForValue (
 /**\r
   Return the buffer pointer for this value.\r
 \r
-  EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to \r
+  EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to\r
   EFI_IFR_TYPE_BUFFER when do the value compare.\r
 \r
   @param  Value                  Expression value to compare on.\r
@@ -1180,13 +1175,13 @@ IfrToString (
   case EFI_IFR_TYPE_BOOLEAN:\r
     String = (Value.Value.b) ? L"True" : L"False";\r
     break;\r
-    \r
+\r
   case EFI_IFR_TYPE_BUFFER:\r
   case EFI_IFR_TYPE_DATE:\r
   case EFI_IFR_TYPE_TIME:\r
   case EFI_IFR_TYPE_REF:\r
     //\r
-    // + 3 is base on the unicode format, the length may be odd number, \r
+    // + 3 is base on the unicode format, the length may be odd number,\r
     // so need 1 byte to align, also need 2 bytes for L'\0'.\r
     //\r
     if (Value.Type == EFI_IFR_TYPE_BUFFER) {\r
@@ -1201,20 +1196,20 @@ IfrToString (
     ASSERT (TmpBuf != NULL);\r
     if (Format == EFI_IFR_STRING_ASCII) {\r
       CopyMem (TmpBuf, SrcBuf, SrcLen);\r
-      PrintFormat = L"%a"; \r
+      PrintFormat = L"%a";\r
     } else {\r
       // Format == EFI_IFR_STRING_UNICODE\r
       CopyMem (TmpBuf, SrcBuf, SrcLen * sizeof (CHAR16));\r
-      PrintFormat = L"%s";  \r
+      PrintFormat = L"%s";\r
     }\r
     UnicodeSPrint (Buffer, sizeof (Buffer), PrintFormat, TmpBuf);\r
-    String = Buffer; \r
+    String = Buffer;\r
     FreePool (TmpBuf);\r
     if (Value.Type == EFI_IFR_TYPE_BUFFER) {\r
       FreePool (Value.Buffer);\r
     }\r
     break;\r
-    \r
+\r
   default:\r
     Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
     return EFI_SUCCESS;\r
@@ -1286,7 +1281,10 @@ IfrToUint (
       Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
       return EFI_SUCCESS;\r
     }\r
+\r
+    ASSERT (GetBufferForValue (&Value) != NULL);\r
     Result->Value.u64 = *(UINT64*) GetBufferForValue (&Value);\r
+\r
     if (Value.Type == EFI_IFR_TYPE_BUFFER) {\r
       FreePool (Value.Buffer);\r
     }\r
@@ -1323,6 +1321,8 @@ IfrCatenate (
   UINTN          Size;\r
   UINT16         Length0;\r
   UINT16         Length1;\r
+  UINT8          *TmpBuf;\r
+  UINTN          MaxLen;\r
 \r
   //\r
   // String[0] - The second string\r
@@ -1362,10 +1362,11 @@ IfrCatenate (
 \r
   if (Value[0].Type == EFI_IFR_TYPE_STRING) {\r
     Size = StrSize (String[0]);\r
-    StringPtr= AllocatePool (StrSize (String[1]) + Size);\r
+    MaxLen = (StrSize (String[1]) + Size) / sizeof (CHAR16);\r
+    StringPtr= AllocatePool (MaxLen * sizeof (CHAR16));\r
     ASSERT (StringPtr != NULL);\r
-    StrCpy (StringPtr, String[1]);\r
-    StrCat (StringPtr, String[0]);\r
+    StrCpyS (StringPtr, MaxLen, String[1]);\r
+    StrCatS (StringPtr, MaxLen, String[0]);\r
 \r
     Result->Type = EFI_IFR_TYPE_STRING;\r
     Result->Value.string = NewString (StringPtr, FormSet->HiiHandle);\r
@@ -1378,8 +1379,12 @@ IfrCatenate (
     Result->Buffer = AllocateZeroPool (Result->BufferLen);\r
     ASSERT (Result->Buffer != NULL);\r
 \r
-    CopyMem (Result->Buffer, GetBufferForValue(&Value[0]), Length0);\r
-    CopyMem (&Result->Buffer[Length0], GetBufferForValue(&Value[1]), Length1);\r
+    TmpBuf = GetBufferForValue(&Value[0]);\r
+    ASSERT (TmpBuf != NULL);\r
+    CopyMem (Result->Buffer, TmpBuf, Length0);\r
+    TmpBuf = GetBufferForValue(&Value[1]);\r
+    ASSERT (TmpBuf != NULL);\r
+    CopyMem (&Result->Buffer[Length0], TmpBuf, Length1);\r
   }\r
 Done:\r
   if (Value[0].Buffer != NULL) {\r
@@ -1470,6 +1475,180 @@ Done:
   return Status;\r
 }\r
 \r
+/**\r
+  Evaluate opcode EFI_IFR_MATCH2.\r
+\r
+  @param  FormSet                Formset which contains this opcode.\r
+  @param  SyntaxType             Syntax type for match2.\r
+  @param  Result                 Evaluation result for this opcode.\r
+\r
+  @retval EFI_SUCCESS            Opcode evaluation success.\r
+  @retval Other                  Opcode evaluation failed.\r
+\r
+**/\r
+EFI_STATUS\r
+IfrMatch2 (\r
+  IN FORM_BROWSER_FORMSET  *FormSet,\r
+  IN EFI_GUID              *SyntaxType,\r
+  OUT  EFI_HII_VALUE       *Result\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_HII_VALUE                    Value[2];\r
+  CHAR16                           *String[2];\r
+  UINTN                            Index;\r
+  UINTN                            GuidIndex;\r
+  EFI_HANDLE                       *HandleBuffer;\r
+  UINTN                            BufferSize;\r
+  EFI_REGULAR_EXPRESSION_PROTOCOL  *RegularExpressionProtocol;\r
+  UINTN                            RegExSyntaxTypeListSize;\r
+  EFI_REGEX_SYNTAX_TYPE            *RegExSyntaxTypeList;\r
+  UINTN                            CapturesCount;\r
+\r
+  //\r
+  // String[0] - The string to search\r
+  // String[1] - pattern\r
+  //\r
+  String[0] = NULL;\r
+  String[1] = NULL;\r
+  HandleBuffer = NULL;\r
+  RegExSyntaxTypeList = NULL;\r
+  Status = EFI_SUCCESS;\r
+  ZeroMem (Value, sizeof (Value));\r
+\r
+  Status = PopExpression (&Value[0]);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Status = PopExpression (&Value[1]);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  for (Index = 0; Index < 2; Index++) {\r
+    if (Value[Index].Type != EFI_IFR_TYPE_STRING) {\r
+      Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
+      Status = EFI_SUCCESS;\r
+      goto Done;\r
+    }\r
+\r
+    String[Index] = GetToken (Value[Index].Value.string, FormSet->HiiHandle);\r
+    if (String [Index] == NULL) {\r
+      Status = EFI_NOT_FOUND;\r
+      goto Done;\r
+    }\r
+  }\r
+\r
+  BufferSize    = 0;\r
+  HandleBuffer  = NULL;\r
+  Status = gBS->LocateHandle(\r
+                      ByProtocol,\r
+                      &gEfiRegularExpressionProtocolGuid,\r
+                      NULL,\r
+                      &BufferSize,\r
+                      HandleBuffer);\r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    HandleBuffer = AllocateZeroPool(BufferSize);\r
+    if (HandleBuffer == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Done;\r
+    }\r
+    Status = gBS->LocateHandle(\r
+                        ByProtocol,\r
+                        &gEfiRegularExpressionProtocolGuid,\r
+                        NULL,\r
+                        &BufferSize,\r
+                        HandleBuffer);\r
+\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
+    Status = EFI_SUCCESS;\r
+    goto Done;\r
+  }\r
+\r
+  ASSERT (HandleBuffer != NULL);\r
+  for ( Index = 0; Index < BufferSize / sizeof(EFI_HANDLE); Index ++) {\r
+    Status = gBS->HandleProtocol (\r
+                  HandleBuffer[Index],\r
+                  &gEfiRegularExpressionProtocolGuid,\r
+                  (VOID**)&RegularExpressionProtocol\r
+                 );\r
+    if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+    }\r
+\r
+    RegExSyntaxTypeListSize = 0;\r
+    RegExSyntaxTypeList = NULL;\r
+\r
+    Status = RegularExpressionProtocol->GetInfo (\r
+                                          RegularExpressionProtocol,\r
+                                          &RegExSyntaxTypeListSize,\r
+                                          RegExSyntaxTypeList\r
+                                          );\r
+    if (Status == EFI_BUFFER_TOO_SMALL) {\r
+      RegExSyntaxTypeList = AllocateZeroPool(RegExSyntaxTypeListSize);\r
+      if (RegExSyntaxTypeList == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        goto Done;\r
+      }\r
+      Status = RegularExpressionProtocol->GetInfo (\r
+                                            RegularExpressionProtocol,\r
+                                            &RegExSyntaxTypeListSize,\r
+                                            RegExSyntaxTypeList\r
+                                            );\r
+    } else if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+    }\r
+\r
+    for (GuidIndex = 0; GuidIndex < RegExSyntaxTypeListSize / sizeof(EFI_GUID); GuidIndex++) {\r
+      if (CompareGuid (&RegExSyntaxTypeList[GuidIndex], SyntaxType)) {\r
+        //\r
+        // Find the match type, return the value.\r
+        //\r
+        Result->Type = EFI_IFR_TYPE_BOOLEAN;\r
+        Status = RegularExpressionProtocol->MatchString (\r
+                                              RegularExpressionProtocol,\r
+                                              String[0],\r
+                                              String[1],\r
+                                              SyntaxType,\r
+                                              &Result->Value.b,\r
+                                              NULL,\r
+                                              &CapturesCount\r
+                                              );\r
+        goto Done;\r
+      }\r
+    }\r
+\r
+    if (RegExSyntaxTypeList != NULL) {\r
+      FreePool (RegExSyntaxTypeList);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Type specified by SyntaxType is not supported\r
+  // in any of the EFI_REGULAR_EXPRESSION_PROTOCOL instances.\r
+  //\r
+  Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
+  Status = EFI_SUCCESS;\r
+\r
+Done:\r
+  if (String[0] != NULL) {\r
+    FreePool (String[0]);\r
+  }\r
+  if (String[1] != NULL) {\r
+    FreePool (String[1]);\r
+  }\r
+  if (RegExSyntaxTypeList != NULL) {\r
+    FreePool (RegExSyntaxTypeList);\r
+  }\r
+  if (HandleBuffer != NULL) {\r
+    FreePool (HandleBuffer);\r
+  }\r
+  return Status;\r
+}\r
 \r
 /**\r
   Evaluate opcode EFI_IFR_FIND.\r
@@ -1515,7 +1694,7 @@ IfrFind (
   Status = PopExpression (&Value[2]);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
-  }  \r
+  }\r
 \r
   if (Value[0].Type > EFI_IFR_TYPE_NUM_SIZE_64) {\r
     Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
@@ -1610,7 +1789,7 @@ IfrMid (
   Status = PopExpression (&Value[2]);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
-  } \r
+  }\r
 \r
   if (Value[0].Type > EFI_IFR_TYPE_NUM_SIZE_64) {\r
     Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
@@ -1656,7 +1835,7 @@ IfrMid (
       Result->BufferLen = 0;\r
       Result->Buffer = NULL;\r
     } else {\r
-      Result->BufferLen = (UINT16)((BufferLen - Base) < Length ? (BufferLen - Base) : Length);    \r
+      Result->BufferLen = (UINT16)((BufferLen - Base) < Length ? (BufferLen - Base) : Length);\r
       Result->Buffer = AllocateZeroPool (Result->BufferLen);\r
       ASSERT (Result->Buffer != NULL);\r
       CopyMem (Result->Buffer, &Buffer[Base], Result->BufferLen);\r
@@ -1666,7 +1845,7 @@ IfrMid (
       FreePool (Value[2].Buffer);\r
     }\r
   }\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -1711,9 +1890,9 @@ IfrToken (
   Status = PopExpression (&Value[2]);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
-  } \r
+  }\r
 \r
-  if (Value[0].Type > EFI_IFR_TYPE_NUM_SIZE_64) { \r
+  if (Value[0].Type > EFI_IFR_TYPE_NUM_SIZE_64) {\r
     Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
     return EFI_SUCCESS;\r
   }\r
@@ -1728,7 +1907,7 @@ IfrToken (
   for (Index = 0; Index < 2; Index++) {\r
     if (Value[Index + 1].Type != EFI_IFR_TYPE_STRING) {\r
       Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
-      Status = EFI_SUCCESS;   \r
+      Status = EFI_SUCCESS;\r
       goto Done;\r
     }\r
 \r
@@ -1826,7 +2005,7 @@ IfrSpan (
   Status = PopExpression (&Value[2]);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
-  } \r
+  }\r
 \r
   if (Value[0].Type > EFI_IFR_TYPE_NUM_SIZE_64) {\r
     Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
@@ -2074,7 +2253,7 @@ CompareHiiValue (
     Buf1Len = GetLengthForValue(Value1);\r
     Buf2    = GetBufferForValue(Value2);\r
     Buf2Len = GetLengthForValue(Value2);\r
-    \r
+\r
     Len = Buf1Len > Buf2Len ? Buf2Len : Buf1Len;\r
     *Result = CompareMem (Buf1, Buf2, Len);\r
     if ((*Result == 0) && (Buf1Len != Buf2Len)) {\r
@@ -2085,7 +2264,7 @@ CompareHiiValue (
       *Result = Buf1Len > Buf2Len ? 1 : -1;\r
     }\r
     return EFI_SUCCESS;\r
-  }  \r
+  }\r
 \r
   //\r
   // Take types(integer, boolean) as integer\r
@@ -2152,7 +2331,7 @@ CheckUserPrivilege (
   /// Enumerate all user information of the current user profile\r
   /// to look for any EFI_USER_INFO_ACCESS_SETUP record.\r
   ///\r
-  \r
+\r
   for (UserInfoHandle = NULL;;) {\r
     Status = mUserManager->GetNextInfo (mUserManager, UserProfileHandle, &UserInfoHandle);\r
     if (EFI_ERROR (Status)) {\r
@@ -2217,11 +2396,11 @@ CheckUserPrivilege (
   @param  FormSetGuid            The formset guid which include the question.\r
   @param  QuestionId             The question id which need to get value from.\r
   @param  Value                  The return data about question's value.\r
-  \r
+\r
   @retval TRUE                   Get the question value success.\r
   @retval FALSE                  Get the question value failed.\r
 **/\r
-BOOLEAN \r
+BOOLEAN\r
 GetQuestionValueFromForm (\r
   IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
   IN EFI_HII_HANDLE            InputHiiHandle,\r
@@ -2238,10 +2417,10 @@ GetQuestionValueFromForm (
   BOOLEAN                      GetTheVal;\r
   LIST_ENTRY                   *Link;\r
 \r
-  // \r
-  // The input parameter DevicePath or InputHiiHandle must have one valid input. \r
   //\r
-  ASSERT ((DevicePath != NULL && InputHiiHandle == NULL) || \r
+  // The input parameter DevicePath or InputHiiHandle must have one valid input.\r
+  //\r
+  ASSERT ((DevicePath != NULL && InputHiiHandle == NULL) ||\r
           (DevicePath == NULL && InputHiiHandle != NULL) );\r
 \r
   GetTheVal    = TRUE;\r
@@ -2259,7 +2438,7 @@ GetQuestionValueFromForm (
     }\r
   } else {\r
     HiiHandle = InputHiiHandle;\r
-  } \r
+  }\r
   ASSERT (HiiHandle != NULL);\r
 \r
   //\r
@@ -2275,7 +2454,7 @@ GetQuestionValueFromForm (
 \r
   //\r
   // Base on the Question Id to get the question info.\r
-  //  \r
+  //\r
   Question = IdToQuestion(FormSet, NULL, QuestionId);\r
   if (Question == NULL) {\r
     GetTheVal = FALSE;\r
@@ -2298,18 +2477,18 @@ GetQuestionValueFromForm (
     Form = NULL;\r
   }\r
   ASSERT (Form != NULL);\r
-  \r
+\r
   //\r
   // Get the question value.\r
   //\r
-  Status = GetQuestionValue(FormSet, Form, Question, GetSetValueWithHiiDriver);\r
+  Status = GetQuestionValue(FormSet, Form, Question, GetSetValueWithEditBuffer);\r
   if (EFI_ERROR (Status)) {\r
     GetTheVal = FALSE;\r
     goto Done;\r
   }\r
 \r
   CopyMem (Value, &Question->HiiValue, sizeof (EFI_HII_VALUE));\r
-  \r
+\r
 Done:\r
   //\r
   // Clean the formset structure and restore the global parameter.\r
@@ -2317,7 +2496,7 @@ Done:
   if (FormSet != NULL) {\r
     DestroyFormSet (FormSet);\r
   }\r
-  \r
+\r
   return GetTheVal;\r
 }\r
 \r
@@ -2372,6 +2551,8 @@ EvaluateExpression (
   EFI_HII_VALUE           QuestionVal;\r
   EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
 \r
+  StrPtr = NULL;\r
+\r
   //\r
   // Save current stack offset.\r
   //\r
@@ -2521,7 +2702,7 @@ EvaluateExpression (
                     TempBuffer [Index/2] = (UINT8) ((DigitUint8 << 4) + TempBuffer [Index/2]);\r
                   }\r
                 }\r
-              }                \r
+              }\r
             }\r
           }\r
           break;\r
@@ -2620,7 +2801,7 @@ EvaluateExpression (
       if (EFI_ERROR (Status)) {\r
         goto Done;\r
       }\r
-    \r
+\r
       //\r
       // Validate the expression value\r
       //\r
@@ -2646,7 +2827,7 @@ EvaluateExpression (
         if (StrPtr != NULL) {\r
           FreePool (StrPtr);\r
         }\r
-      } else if (CompareGuid (&OpCode->Guid, &gZeroGuid) != 0) {\r
+      } else if (IsZeroGuid (&OpCode->Guid)) {\r
         if (!GetQuestionValueFromForm(NULL, FormSet->HiiHandle, &OpCode->Guid, Value->Value.u16, &QuestionVal)){\r
           Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
           break;\r
@@ -2833,14 +3014,14 @@ EvaluateExpression (
         //\r
         // When converting from a string, if case-insensitive compare\r
         // with "true" is True, then push True. If a case-insensitive compare\r
-        // with "false" is True, then push False. Otherwise, push Undefined. \r
+        // with "false" is True, then push False. Otherwise, push Undefined.\r
         //\r
         StrPtr = GetToken (Value->Value.string, FormSet->HiiHandle);\r
         if (StrPtr == NULL) {\r
           Status = EFI_INVALID_PARAMETER;\r
           goto Done;\r
         }\r
-        \r
+\r
         IfrStrToUpper (StrPtr);\r
         if (StrCmp (StrPtr, L"TRUE") == 0){\r
           Value->Value.b = TRUE;\r
@@ -2854,11 +3035,11 @@ EvaluateExpression (
         FreePool (StrPtr);\r
       } else if (Value->Type == EFI_IFR_TYPE_BUFFER) {\r
         //\r
-        // When converting from a buffer, if the buffer is all zeroes, \r
-        // then push False. Otherwise push True. \r
+        // When converting from a buffer, if the buffer is all zeroes,\r
+        // then push False. Otherwise push True.\r
         //\r
         for (Index =0; Index < Value->BufferLen; Index ++) {\r
-          if (Value->Buffer[Index] != 0) {            \r
+          if (Value->Buffer[Index] != 0) {\r
             break;\r
           }\r
         }\r
@@ -2953,14 +3134,21 @@ EvaluateExpression (
         case EFI_HII_VARSTORE_NAME_VALUE:\r
           if (OpCode->ValueType != EFI_IFR_TYPE_STRING) {\r
             NameValue = AllocateZeroPool ((OpCode->ValueWidth * 2 + 1) * sizeof (CHAR16));\r
-            ASSERT (Value != NULL);\r
+            ASSERT (NameValue != NULL);\r
             //\r
             // Convert Buffer to Hex String\r
             //\r
             TempBuffer = (UINT8 *) &Value->Value + OpCode->ValueWidth - 1;\r
             StrPtr = NameValue;\r
             for (Index = 0; Index < OpCode->ValueWidth; Index ++, TempBuffer --) {\r
-              StrPtr += UnicodeValueToString (StrPtr, PREFIX_ZERO | RADIX_HEX, *TempBuffer, 2);\r
+              UnicodeValueToStringS (\r
+                StrPtr,\r
+                (OpCode->ValueWidth * 2 + 1) * sizeof (CHAR16) - ((UINTN)StrPtr - (UINTN)NameValue),\r
+                PREFIX_ZERO | RADIX_HEX,\r
+                *TempBuffer,\r
+                2\r
+                );\r
+              StrPtr += StrnLenS (StrPtr, OpCode->ValueWidth * 2 + 1 - ((UINTN)StrPtr - (UINTN)NameValue) / sizeof (CHAR16));\r
             }\r
             Status = SetValueByName (OpCode->VarStorage, OpCode->ValueName, NameValue, GetSetValueWithEditBuffer, NULL);\r
             FreePool (NameValue);\r
@@ -2987,7 +3175,6 @@ EvaluateExpression (
           //\r
           Status = EFI_UNSUPPORTED;\r
           goto Done;\r
-          break;\r
         }\r
       } else {\r
         //\r
@@ -3189,15 +3376,15 @@ EvaluateExpression (
         goto Done;\r
       }\r
 \r
-      if (Data2.Type > EFI_IFR_TYPE_BOOLEAN && \r
-          Data2.Type != EFI_IFR_TYPE_STRING && \r
+      if (Data2.Type > EFI_IFR_TYPE_BOOLEAN &&\r
+          Data2.Type != EFI_IFR_TYPE_STRING &&\r
           !IsTypeInBuffer(&Data2)) {\r
         Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
         break;\r
       }\r
 \r
-      if (Data1.Type > EFI_IFR_TYPE_BOOLEAN && \r
-          Data1.Type != EFI_IFR_TYPE_STRING && \r
+      if (Data1.Type > EFI_IFR_TYPE_BOOLEAN &&\r
+          Data1.Type != EFI_IFR_TYPE_STRING &&\r
           !IsTypeInBuffer(&Data1)) {\r
         Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
         break;\r
@@ -3210,7 +3397,7 @@ EvaluateExpression (
       if (Data2.Type == EFI_IFR_TYPE_BUFFER) {\r
         FreePool (Data2.Buffer);\r
       }\r
-      \r
+\r
       if (Status == EFI_UNSUPPORTED) {\r
         Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
         Status = EFI_SUCCESS;\r
@@ -3256,10 +3443,14 @@ EvaluateExpression (
       if (EFI_ERROR (Status)) {\r
         goto Done;\r
       }\r
-     \r
+\r
       Status = IfrMatch (FormSet, Value);\r
       break;\r
 \r
+    case EFI_IFR_MATCH2_OP:\r
+      Status = IfrMatch2 (FormSet, &OpCode->Guid, Value);\r
+      break;\r
+\r
     case EFI_IFR_CATENATE_OP:\r
       Status = IfrCatenate (FormSet, Value);\r
       break;\r
@@ -3430,7 +3621,7 @@ Done:
 \r
 /**\r
   Check whether the result is TRUE or FALSE.\r
-  \r
+\r
   For the EFI_HII_VALUE value type is numeric, return TRUE if the\r
   value is not 0.\r
 \r
@@ -3467,20 +3658,20 @@ IsTrue (
 }\r
 \r
 /**\r
-  Return the result of the expression list. Check the expression list and \r
-  return the highest priority express result.  \r
+  Return the result of the expression list. Check the expression list and\r
+  return the highest priority express result.\r
   Priority: DisableIf > SuppressIf > GrayOutIf > FALSE\r
 \r
   @param  ExpList             The input expression list.\r
   @param  Evaluate            Whether need to evaluate the expression first.\r
   @param  FormSet             FormSet associated with this expression.\r
-  @param  Form                Form associated with this expression.  \r
+  @param  Form                Form associated with this expression.\r
 \r
-  @retval EXPRESS_RESULT      Return the higher priority express result. \r
+  @retval EXPRESS_RESULT      Return the higher priority express result.\r
                               DisableIf > SuppressIf > GrayOutIf > FALSE\r
 \r
 **/\r
-EXPRESS_RESULT \r
+EXPRESS_RESULT\r
 EvaluateExpressionList (\r
   IN FORM_EXPRESSION_LIST *ExpList,\r
   IN BOOLEAN              Evaluate,\r
@@ -3503,7 +3694,7 @@ EvaluateExpressionList (
   //\r
   // Check whether need to evaluate the expression first.\r
   //\r
-  if (Evaluate) {  \r
+  if (Evaluate) {\r
     while (ExpList->Count > Index) {\r
       Status = EvaluateExpression (FormSet, Form, ExpList->Expression[Index++]);\r
       if (EFI_ERROR (Status)) {\r
@@ -3532,12 +3723,12 @@ EvaluateExpressionList (
           break;\r
 \r
         default:\r
-          return ExpressFalse; \r
+          return ExpressFalse;\r
       }\r
 \r
       ReturnVal = ReturnVal < CompareOne ? CompareOne : ReturnVal;\r
     }\r
   }\r
-  \r
+\r
   return ReturnVal;\r
 }\r