]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg:Make the logic in ConfigRouting.c clear and safe
authorDandan Bi <dandan.bi@intel.com>
Tue, 26 Jan 2016 09:42:58 +0000 (09:42 +0000)
committerdandanbi <dandanbi@Edk2>
Tue, 26 Jan 2016 09:42:58 +0000 (09:42 +0000)
The BlockData is expected to be NULL when to call function
IsThisOpcodeRequired in each opcode,but now exists case that the
Blockdata not be cleaned,then will be used in other opcode.it
is not correct,now add the check before use.

The comments and logic in function IsThisOpcodeRequired are not
consistent,now refine the code to make the logic clear.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19749 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c

index 8f0b96847dd184379564f639fb1cb62617b38cfd..3a871cf3baed0e723da11076110c95632d56c76a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.\r
 \r
-Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2016, 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
@@ -1466,7 +1466,8 @@ Done:
   @param  ReturnData             The data block added for this opcode.\r
 \r
   @retval  EFI_SUCCESS           This opcode is required.\r
-  @retval  Others                This opcode is not required or error occur.\r
+  @retval  EFI_NOT_FOUND         This opcode is not required.\r
+  @retval  Others                Contain some error.\r
                                  \r
 **/\r
 EFI_STATUS\r
@@ -1498,7 +1499,7 @@ IsThisOpcodeRequired (
       //\r
       // This question is not in the requested string. Skip it.\r
       //\r
-      return EFI_SUCCESS;\r
+      return EFI_NOT_FOUND;\r
     }\r
   } else {\r
     VarOffset = IfrQuestionHdr->VarStoreInfo.VarOffset;\r
@@ -1510,7 +1511,7 @@ IsThisOpcodeRequired (
       //\r
       // This question is not in the requested string. Skip it.\r
       //\r
-      return EFI_SUCCESS;\r
+      return EFI_NOT_FOUND;\r
     }\r
 \r
     //\r
@@ -1772,8 +1773,21 @@ ParseIfrData (
       }\r
       VarWidth  = (UINT16) (sizeof (EFI_HII_REF));\r
 \r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
       break;\r
@@ -1800,17 +1814,28 @@ ParseIfrData (
       }\r
       VarWidth  = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));\r
 \r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
 \r
-      if (BlockData == NULL) {\r
-        //\r
-        // BlockData == NULL means this opcode is not in the requst array.\r
-        //\r
-        break;\r
-      }\r
+      //\r
+      //when go to there,BlockData can't be NULLL.\r
+      //\r
+      ASSERT (BlockData != NULL);\r
 \r
       if (IfrOpHdr->OpCode == EFI_IFR_ONE_OF_OP) {\r
         //\r
@@ -1877,8 +1902,22 @@ ParseIfrData (
         break;\r
       }\r
       VarWidth  = IfrOrderedList->MaxContainers;\r
+\r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
       break;\r
@@ -1908,17 +1947,29 @@ ParseIfrData (
         break;\r
       }\r
       VarWidth  = (UINT16) sizeof (BOOLEAN);\r
+\r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
 \r
-      if (BlockData == NULL) {\r
-        //\r
-        // BlockData == NULL means this opcode is not in the requst array.\r
-        //\r
-        break;\r
-      }\r
+      //\r
+      //when go to there,BlockData can't be NULLL.\r
+      //\r
+      ASSERT (BlockData != NULL);\r
 \r
       //\r
       // Add default value for standard ID by CheckBox Flag\r
@@ -1995,9 +2046,22 @@ ParseIfrData (
         break;\r
       }\r
 \r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       VarWidth  = (UINT16) sizeof (EFI_HII_DATE);\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
       break;\r
@@ -2024,9 +2088,22 @@ ParseIfrData (
         break;\r
       }\r
 \r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       VarWidth  = (UINT16) sizeof (EFI_HII_TIME);\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
       break;\r
@@ -2053,9 +2130,22 @@ ParseIfrData (
         break;\r
       }\r
 \r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       VarWidth  = (UINT16) (IfrString->MaxSize * sizeof (UINT16));\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
       break;\r
@@ -2082,9 +2172,22 @@ ParseIfrData (
         break;\r
       }\r
 \r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       VarWidth  = (UINT16) (IfrPassword->MaxSize * sizeof (UINT16));\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
 \r
@@ -2288,6 +2391,14 @@ ParseIfrData (
     PackageOffset += IfrOpHdr->Length;\r
   }\r
 \r
+  //\r
+  //if Status == EFI_NOT_FOUND, just means the opcode is not required,not contain any error,\r
+  //so set the Status to EFI_SUCCESS.\r
+  //\r
+  if (Status == EFI_NOT_FOUND){\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
 Done:\r
   for (LinkData = VarStorageData->BlockEntry.ForwardLink; LinkData != &VarStorageData->BlockEntry; LinkData = LinkData->ForwardLink) {\r
     BlockData = BASE_CR (LinkData, IFR_BLOCK_DATA, Entry);\r