]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/ProcessOptions.c
Add code check to avoid access violation.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / ProcessOptions.c
index e654545bf73e84d28c26eb000d495447122c866d..c388247a88ff3b044f884c8c83ea1b7649b03b6f 100644 (file)
@@ -2,7 +2,7 @@
 Implementation for handling the User Interface option processing.\r
 \r
 \r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2012, 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
@@ -84,12 +84,13 @@ ValueToOption (
 {\r
   LIST_ENTRY       *Link;\r
   QUESTION_OPTION  *Option;\r
+  INTN             Result;\r
 \r
   Link = GetFirstNode (&Question->OptionListHead);\r
   while (!IsNull (&Question->OptionListHead, Link)) {\r
     Option = QUESTION_OPTION_FROM_LINK (Link);\r
 \r
-    if (CompareHiiValue (&Option->Value, OptionValue, NULL) == 0) {\r
+    if ((CompareHiiValue (&Option->Value, OptionValue, &Result, NULL) == EFI_SUCCESS) && (Result == 0)) {\r
       return Option;\r
     }\r
 \r
@@ -482,7 +483,7 @@ ProcessOptions (
           SetArrayData (ValueArray, ValueType, Index2, 0);\r
 \r
           Status = SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
-          UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+          UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
 \r
           FreePool (*OptionString);\r
           *OptionString = NULL;\r
@@ -491,7 +492,7 @@ ProcessOptions (
 \r
         Suppress = FALSE;\r
         if ((OneOfOption->SuppressExpression != NULL) &&\r
-            (OneOfOption->SuppressExpression->Result.Value.b)) {\r
+            (EvaluateExpressionList(OneOfOption->SuppressExpression, FALSE, NULL, NULL) == ExpressSuppress)) {\r
           //\r
           // This option is suppressed\r
           //\r
@@ -502,6 +503,7 @@ ProcessOptions (
           Character[0] = LEFT_ONEOF_DELIMITER;\r
           NewStrCat (OptionString[0], Character);\r
           StringPtr = GetToken (OneOfOption->Text, Selection->Handle);\r
+          ASSERT (StringPtr != NULL);\r
           NewStrCat (OptionString[0], StringPtr);\r
           Character[0] = RIGHT_ONEOF_DELIMITER;\r
           NewStrCat (OptionString[0], Character);\r
@@ -547,10 +549,10 @@ ProcessOptions (
           Option = QUESTION_OPTION_FROM_LINK (Link);\r
 \r
           if ((Option->SuppressExpression == NULL) ||\r
-              !Option->SuppressExpression->Result.Value.b) {\r
+              (EvaluateExpressionList(Option->SuppressExpression, FALSE, NULL, NULL) == ExpressFalse)) {\r
             CopyMem (QuestionValue, &Option->Value, sizeof (EFI_HII_VALUE));\r
             SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
-            UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+            UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
             break;\r
           }\r
 \r
@@ -563,7 +565,7 @@ ProcessOptions (
       }\r
 \r
       if ((OneOfOption->SuppressExpression != NULL) &&\r
-          (OneOfOption->SuppressExpression->Result.Value.b)) {\r
+          ((EvaluateExpressionList(OneOfOption->SuppressExpression, FALSE, NULL, NULL) == ExpressSuppress))) {\r
         //\r
         // This option is suppressed\r
         //\r
@@ -582,12 +584,12 @@ ProcessOptions (
           OneOfOption = QUESTION_OPTION_FROM_LINK (Link);\r
 \r
           if ((OneOfOption->SuppressExpression == NULL) ||\r
-              !OneOfOption->SuppressExpression->Result.Value.b) {\r
+              (EvaluateExpressionList(OneOfOption->SuppressExpression, FALSE, NULL, NULL) == ExpressFalse)) {\r
             Suppress = FALSE;\r
             CopyMem (QuestionValue, &OneOfOption->Value, sizeof (EFI_HII_VALUE));\r
             SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
-            UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
-            gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
+            UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+            gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND);\r
             break;\r
           }\r
 \r
@@ -599,6 +601,7 @@ ProcessOptions (
         Character[0] = LEFT_ONEOF_DELIMITER;\r
         NewStrCat (OptionString[0], Character);\r
         StringPtr = GetToken (OneOfOption->Text, Selection->Handle);\r
+        ASSERT (StringPtr != NULL);\r
         NewStrCat (OptionString[0], StringPtr);\r
         Character[0] = RIGHT_ONEOF_DELIMITER;\r
         NewStrCat (OptionString[0], Character);\r
@@ -638,7 +641,7 @@ ProcessOptions (
       // Save Question value\r
       //\r
       Status = SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
-      UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+      UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
     }\r
 \r
     if (QuestionValue->Value.b) {\r
@@ -697,7 +700,7 @@ ProcessOptions (
 \r
       case 2:\r
         SetUnicodeMem (OptionString[0], 7, L' ');\r
-        UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%4d", QuestionValue->Value.date.Year);\r
+        UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%04d", QuestionValue->Value.date.Year);\r
         *(OptionString[0] + 11) = RIGHT_NUMERIC_DELIMITER;\r
         break;\r
       }\r
@@ -740,6 +743,7 @@ ProcessOptions (
     if (Selected) {\r
       StringPtr = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));\r
       ASSERT (StringPtr);\r
+      CopyMem(StringPtr, Question->BufferValue, Maximum * sizeof (CHAR16));\r
 \r
       Status = ReadString (MenuOption, gPromptForData, StringPtr);\r
       if (!EFI_ERROR (Status)) {\r
@@ -751,7 +755,7 @@ ProcessOptions (
           CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));\r
           SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
 \r
-          UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+          UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
         }\r
       }\r
 \r