]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c
Add in ASSERT to avoid NULL point dereference.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / IfrParse.c
index 7a09b32b738df9d7a0b54a3757dc9cd7ab2f0114..1f8ebf968dd27e81d452ef5e4055350c0beed578 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Parser for IFR binary encoding.\r
 \r
-Copyright (c) 2007 - 2008, Intel Corporation\r
+Copyright (c) 2007 - 2009, Intel Corporation\r
 All rights reserved. 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
@@ -852,6 +852,7 @@ ParseOpCodes (
   CurrentDefault           = NULL;\r
   CurrentOption            = NULL;\r
   OptionSuppressExpression = NULL;\r
+  ImageId                  = NULL;\r
 \r
   //\r
   // Get the number of Statements and Expressions\r
@@ -1059,11 +1060,12 @@ ParseOpCodes (
           //\r
           // Evaluate DisableIf expression\r
           //\r
-          ASSERT (CurrentExpression != NULL);\r
           Status = EvaluateExpression (FormSet, CurrentForm, CurrentExpression);\r
           if (EFI_ERROR (Status)) {\r
             return Status;\r
           }\r
+\r
+          ASSERT (CurrentExpression != NULL);\r
           if (CurrentExpression->Result.Type != EFI_IFR_TYPE_BOOLEAN) {\r
             return EFI_INVALID_PARAMETER;\r
           }\r
@@ -1193,6 +1195,8 @@ ParseOpCodes (
     //\r
     case EFI_IFR_SUBTITLE_OP:\r
       CurrentStatement = CreateStatement (OpCodeData, FormSet, CurrentForm);\r
+      ASSERT (CurrentStatement != NULL);\r
+      \r
       CurrentStatement->Flags = ((EFI_IFR_SUBTITLE *) OpCodeData)->Flags;\r
 \r
       if (Scope != 0) {\r
@@ -1202,6 +1206,7 @@ ParseOpCodes (
 \r
     case EFI_IFR_TEXT_OP:\r
       CurrentStatement = CreateStatement (OpCodeData, FormSet, CurrentForm);\r
+      ASSERT (CurrentStatement != NULL);\r
 \r
       CopyMem (&CurrentStatement->TextTwo, &((EFI_IFR_TEXT *) OpCodeData)->TextTwo, sizeof (EFI_STRING_ID));\r
       break;\r
@@ -1211,6 +1216,7 @@ ParseOpCodes (
     //\r
     case EFI_IFR_ACTION_OP:\r
       CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm);\r
+      ASSERT (CurrentStatement != NULL);\r
 \r
       if (OpCodeLength == sizeof (EFI_IFR_ACTION_1)) {\r
         //\r
@@ -1548,6 +1554,12 @@ ParseOpCodes (
         //\r
         // If used for a question, then the question will be read-only\r
         //\r
+        //\r
+        // Make sure CurrentStatement is not NULL.\r
+        // If it is NULL, 1) ParseOpCodes functions may parse the IFR wrongly. Or 2) the IFR\r
+        // file is wrongly generated by tools such as VFR Compiler. There may be a bug in VFR Compiler.\r
+        //\r
+        ASSERT (CurrentStatement != NULL);\r
         CurrentStatement->ValueExpression = CurrentExpression;\r
       }\r
       break;\r
@@ -1585,10 +1597,17 @@ ParseOpCodes (
         break;\r
 \r
       default:\r
+        //\r
+        // Make sure CurrentStatement is not NULL.\r
+        // If it is NULL, 1) ParseOpCodes functions may parse the IFR wrongly. Or 2) the IFR\r
+        // file is wrongly generated by tools such as VFR Compiler.\r
+        //\r
+        ASSERT (CurrentStatement != NULL);\r
         ImageId = &CurrentStatement->ImageId;\r
         break;\r
       }\r
 \r
+      ASSERT (ImageId != NULL);\r
       CopyMem (ImageId, &((EFI_IFR_IMAGE *) OpCodeData)->Id, sizeof (EFI_IMAGE_ID));\r
       break;\r
 \r
@@ -1596,6 +1615,7 @@ ParseOpCodes (
     // Refresh\r
     //\r
     case EFI_IFR_REFRESH_OP:\r
+      ASSERT (CurrentStatement != NULL);\r
       CurrentStatement->RefreshInterval = ((EFI_IFR_REFRESH *) OpCodeData)->RefreshInterval;\r
       break;\r
 \r
@@ -1720,6 +1740,8 @@ ParseOpCodes (
             if (EFI_ERROR (Status)) {\r
               return Status;\r
             }\r
+\r
+            ASSERT (CurrentExpression != NULL);\r
             if (CurrentExpression->Result.Type != EFI_IFR_TYPE_BOOLEAN) {\r
               return EFI_INVALID_PARAMETER;\r
             }\r