]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Option.c
1. Fix a bug in PXE driver that the PXE boot do not restart if a new boot option...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Option.c
index 11b8978b400581dc6add2a2ff943e4eb99d81e8d..d7700bccc4871c0a312eaa6cd398fa0d9a0ef350 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Function to validate, parse, process the DHCP options.\r
   \r
-Copyright (c) 2006 - 2009, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2009, 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
@@ -542,6 +542,7 @@ DhcpFillOption (
   @param[out] OptionPoint            The array that contains the DHCP options. Caller\r
                                      should free it.\r
 \r
+  @retval EFI_NOT_FOUND          Cannot find any option.\r
   @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory to parse the packet.\r
   @retval EFI_INVALID_PARAMETER  The options are mal-formated\r
   @retval EFI_SUCCESS            The options are parsed into OptionPoint\r
@@ -610,7 +611,7 @@ DhcpParseOption (
   // Allocate a buffer to hold the DHCP options, and after that, a\r
   // continuous buffer to put all the options' data.\r
   //\r
-  Options = AllocateZeroPool (OptNum * sizeof (DHCP_OPTION) + TotalLen);\r
+  Options = AllocateZeroPool ((UINTN) (OptNum * sizeof (DHCP_OPTION)) + TotalLen);\r
 \r
   if (Options == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -624,14 +625,14 @@ DhcpParseOption (
   Status          = DhcpIterateOptions (Packet, DhcpFillOption, &Context);\r
 \r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePool (Options);\r
+    FreePool (Options);\r
     goto ON_EXIT;\r
   }\r
 \r
   *OptionPoint = Options;\r
 \r
 ON_EXIT:\r
-  gBS->FreePool (OptCount);\r
+  FreePool (OptCount);\r
   return Status;\r
 }\r
 \r
@@ -673,13 +674,13 @@ DhcpValidateOptions (
   if (EFI_ERROR (Status) || (Count == 0)) {\r
     return Status;\r
   }\r
+  ASSERT (AllOption != NULL);\r
 \r
   Updated = FALSE;\r
   ZeroMem (&Parameter, sizeof (Parameter));\r
 \r
   for (Index = 0; Index < Count; Index++) {\r
     Option = &AllOption[Index];\r
-    ASSERT (Option != NULL);\r
 \r
     //\r
     // Find the format of the option then validate it.\r
@@ -709,16 +710,15 @@ DhcpValidateOptions (
   }\r
 \r
   if (Updated && (Para != NULL)) {\r
-    if ((*Para = AllocatePool (sizeof (DHCP_PARAMETER))) == NULL) {\r
+    *Para = AllocateCopyPool (sizeof (DHCP_PARAMETER), &Parameter);\r
+    if (*Para == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto ON_EXIT;\r
     }\r
-\r
-    CopyMem (*Para, &Parameter, sizeof (**Para));\r
   }\r
 \r
 ON_EXIT:\r
-  gBS->FreePool (AllOption);\r
+  FreePool (AllOption);\r
   return Status;\r
 }\r
 \r
@@ -754,7 +754,7 @@ DhcpAppendOption (
 \r
     *(Buf++) = Tag;\r
     *(Buf++) = (UINT8) Len;\r
-    CopyMem (Buf, Data + Index * 255, Len);\r
+    CopyMem (Buf, Data + Index * 255, (UINTN) Len);\r
 \r
     Buf     += Len;\r
   }\r
@@ -825,8 +825,10 @@ DhcpBuild (
     goto ON_ERROR;\r
   }\r
 \r
-  for (Index = 0; Index < (UINT32) Count; Index++) {\r
-    Mark[SeedOptions[Index].Tag] = SeedOptions[Index];\r
+  if (SeedOptions != NULL) {\r
+    for (Index = 0; Index < (UINT32) Count; Index++) {\r
+      Mark[SeedOptions[Index].Tag] = SeedOptions[Index];\r
+    }\r
   }\r
 \r
   //\r
@@ -886,9 +888,9 @@ DhcpBuild (
 \r
 ON_ERROR:\r
   if (SeedOptions != NULL) {\r
-    gBS->FreePool (SeedOptions);\r
+    FreePool (SeedOptions);\r
   }\r
 \r
-  gBS->FreePool (Mark);\r
+  FreePool (Mark);\r
   return Status;\r
 }\r