]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c
Enhance the error handling.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / SectionExtraction / CoreSectionExtraction.c
index 9fe296daf8e9345f8a05f4d7e11fdd61d50edb02..8d8f9c8641d00b3f38a87013708dd84d13b2365e 100644 (file)
@@ -27,7 +27,7 @@
   3) A support protocol is not found, and the data is not available to be read\r
      without it.  This results in EFI_PROTOCOL_ERROR.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 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
@@ -619,7 +619,7 @@ EFI_STATUS
 CreateChildNode (\r
   IN     CORE_SECTION_STREAM_NODE              *Stream,\r
   IN     UINT32                                ChildOffset,\r
-     OUT CORE_SECTION_CHILD_NODE               **ChildNode\r
+  OUT    CORE_SECTION_CHILD_NODE               **ChildNode\r
   )\r
 {\r
   EFI_STATUS                                   Status;\r
@@ -674,7 +674,10 @@ CreateChildNode (
       //\r
       // Get the CompressionSectionHeader\r
       //\r
-      ASSERT (Node->Size >= sizeof (EFI_COMPRESSION_SECTION));\r
+      if (Node->Size < sizeof (EFI_COMPRESSION_SECTION)) {\r
+        CoreFreePool (Node);\r
+        return EFI_NOT_FOUND;\r
+      }\r
 \r
       CompressionHeader = (EFI_COMPRESSION_SECTION *) SectionHeader;\r
 \r
@@ -725,8 +728,14 @@ CreateChildNode (
                                  (UINT32 *)&NewStreamBufferSize,\r
                                  &ScratchSize\r
                                  );\r
-          ASSERT_EFI_ERROR (Status);\r
-          ASSERT (NewStreamBufferSize == UncompressedLength);\r
+          if (EFI_ERROR (Status) || (NewStreamBufferSize != UncompressedLength)) {\r
+            CoreFreePool (Node);\r
+            CoreFreePool (NewStreamBuffer);\r
+            if (!EFI_ERROR (Status)) {\r
+              Status = EFI_BAD_BUFFER_SIZE;\r
+            }\r
+            return Status;\r
+          }\r
 \r
           ScratchBuffer = AllocatePool (ScratchSize);\r
           if (ScratchBuffer == NULL) {\r
@@ -744,8 +753,12 @@ CreateChildNode (
                                  ScratchBuffer,\r
                                  ScratchSize\r
                                  );\r
-          ASSERT_EFI_ERROR (Status);\r
           CoreFreePool (ScratchBuffer);\r
+          if (EFI_ERROR (Status)) {\r
+            CoreFreePool (Node);\r
+            CoreFreePool (NewStreamBuffer);\r
+            return Status;\r
+          }\r
         }\r
       } else {\r
         NewStreamBuffer = NULL;\r