]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c
ArmPkg: only attempt buildin MmCommunicationDxe for AArch64
[mirror_edk2.git] / NetworkPkg / Ip6Dxe / Ip6ConfigImpl.c
index 61418e2b9058140cee0324c4e32d507193c0f9be..ab3801336912fde819f8a5883054314666a61cce 100644 (file)
@@ -1,15 +1,10 @@
 /** @file\r
   The implementation of EFI IPv6 Configuration Protocol.\r
 \r
-  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) Microsoft Corporation.<BR>\r
 \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
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -58,7 +53,7 @@ Ip6ConfigOnPolicyChanged (
   BOOLEAN             Recovery;\r
 \r
   Recovery = FALSE;\r
-  \r
+\r
   //\r
   // Currently there are only two policies: Manual and Automatic. Regardless of\r
   // what transition is going on, i.e., Manual -> Automatic and Automatic ->\r
@@ -86,14 +81,14 @@ Ip6ConfigOnPolicyChanged (
   }\r
 \r
   if (!IsListEmpty (&IpSb->DefaultInterface->AddressList) && IpSb->DefaultInterface->AddressCount > 0) {\r
-    //  \r
-    // If any IPv6 children (Instance) in configured state and use global unicast address, it will be \r
-    // destroyed in Ip6RemoveAddr() function later. Then, the upper layer driver's Stop() function will be \r
-    // called, which may break the upper layer network stacks. So, the driver should take the responsibility \r
-    // for the recovery by using ConnectController() after Ip6RemoveAddr(). \r
+    //\r
+    // If any IPv6 children (Instance) in configured state and use global unicast address, it will be\r
+    // destroyed in Ip6RemoveAddr() function later. Then, the upper layer driver's Stop() function will be\r
+    // called, which may break the upper layer network stacks. So, the driver should take the responsibility\r
+    // for the recovery by using ConnectController() after Ip6RemoveAddr().\r
     // Here, just check whether need to recover the upper layer network stacks later.\r
     //\r
-    NET_LIST_FOR_EACH (Entry, &IpSb->DefaultInterface->AddressList) { \r
+    NET_LIST_FOR_EACH (Entry, &IpSb->DefaultInterface->AddressList) {\r
       AddrInfo = NET_LIST_USER_STRUCT_S (Entry, IP6_ADDRESS_INFO, Link, IP6_ADDR_INFO_SIGNATURE);\r
       if (!IsListEmpty (&IpSb->Children)) {\r
         NET_LIST_FOR_EACH (Entry2, &IpSb->Children) {\r
@@ -105,9 +100,9 @@ Ip6ConfigOnPolicyChanged (
         }\r
       }\r
     }\r
-    \r
+\r
     //\r
-    // All IPv6 children that use global unicast address as it's source address\r
+    // All IPv6 children that use global unicast address as its source address\r
     // should be destroyed now. The survivers are those use the link-local address\r
     // or the unspecified address as the source address.\r
     // TODO: Conduct a check here.\r
@@ -118,7 +113,7 @@ Ip6ConfigOnPolicyChanged (
       NULL,\r
       0\r
       );\r
-    \r
+\r
     if (IpSb->Controller != NULL && Recovery) {\r
       //\r
       // ConnectController() to recover the upper layer network stacks.\r
@@ -341,7 +336,7 @@ Ip6ConfigSignalEvent (
 /**\r
   Read the configuration data from variable storage according to the VarName and\r
   gEfiIp6ConfigProtocolGuid. It checks the integrity of variable data. If the\r
-  data is corrupted, it clears the variable data to ZERO. Othewise, it outputs the\r
+  data is corrupted, it clears the variable data to ZERO. Otherwise, it outputs the\r
   configuration data to IP6_CONFIG_INSTANCE.\r
 \r
   @param[in]      VarName  The pointer to the variable name\r
@@ -396,24 +391,9 @@ Ip6ConfigReadConfigData (
                     );\r
     if (EFI_ERROR (Status) || (UINT16) (~NetblockChecksum ((UINT8 *) Variable, (UINT32) VarSize)) != 0) {\r
       //\r
-      // GetVariable still error or the variable is corrupted.\r
-      // Fall back to the default value.\r
+      // GetVariable error or the variable is corrupted.\r
       //\r
-      FreePool (Variable);\r
-\r
-      //\r
-      // Remove the problematic variable and return EFI_NOT_FOUND, a new\r
-      // variable will be set again.\r
-      //\r
-      gRT->SetVariable (\r
-             VarName,\r
-             &gEfiIp6ConfigProtocolGuid,\r
-             IP6_CONFIG_VARIABLE_ATTRIBUTE,\r
-             0,\r
-             NULL\r
-             );\r
-\r
-      return EFI_NOT_FOUND;\r
+      goto Error;\r
     }\r
 \r
     //\r
@@ -438,7 +418,12 @@ Ip6ConfigReadConfigData (
       if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED)) {\r
         //\r
         // This data item has variable length data.\r
+        // Check that the length is contained within the variable before allocating.\r
         //\r
+        if (DataRecord.DataSize > VarSize - DataRecord.Offset) {\r
+          goto Error;\r
+        }\r
+\r
         DataItem->Data.Ptr = AllocatePool (DataRecord.DataSize);\r
         if (DataItem->Data.Ptr == NULL) {\r
           //\r
@@ -460,6 +445,28 @@ Ip6ConfigReadConfigData (
   }\r
 \r
   return Status;\r
+\r
+Error:\r
+  //\r
+  // Fall back to the default value.\r
+  //\r
+  if (Variable != NULL) {\r
+    FreePool (Variable);\r
+  }\r
+\r
+  //\r
+  // Remove the problematic variable and return EFI_NOT_FOUND, a new\r
+  // variable will be set again.\r
+  //\r
+  gRT->SetVariable (\r
+         VarName,\r
+         &gEfiIp6ConfigProtocolGuid,\r
+         IP6_CONFIG_VARIABLE_ATTRIBUTE,\r
+         0,\r
+         NULL\r
+         );\r
+\r
+  return EFI_NOT_FOUND;\r
 }\r
 \r
 /**\r
@@ -618,7 +625,7 @@ Ip6ConfigGetIfInfo (
 }\r
 \r
 /**\r
-  The work function for EfiIp6ConfigSetData() to set the alternative inteface ID\r
+  The work function for EfiIp6ConfigSetData() to set the alternative interface ID\r
   for the communication device managed by this IP6Config instance, if the link local\r
   IPv6 addresses generated from the interface ID based on the default source the\r
   EFI IPv6 Protocol uses is a duplicate address.\r
@@ -726,7 +733,7 @@ Ip6ConfigSetPolicy (
     DataItem->DataSize = 0;\r
     DataItem->Status   = EFI_NOT_FOUND;\r
     NetMapIterate (&DataItem->EventMap, Ip6ConfigSignalEvent, NULL);\r
-    \r
+\r
     if (NewPolicy == Ip6ConfigPolicyManual) {\r
       //\r
       // The policy is changed from automatic to manual. Stop the DHCPv6 process\r
@@ -921,7 +928,7 @@ Ip6ManualAddrDadCallback (
                                 under the current policy.\r
   @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.\r
   @retval EFI_OUT_OF_RESOURCES  Fail to allocate resource to complete the operation.\r
-  @retval EFI_NOT_READY         An asynchrous process is invoked to set the specified\r
+  @retval EFI_NOT_READY         An asynchronous process is invoked to set the specified\r
                                 configuration data, and the process is not finished.\r
   @retval EFI_ABORTED           The manual addresses to be set equal current\r
                                 configuration.\r
@@ -1466,7 +1473,7 @@ Ip6ConfigSetDnsServer (
   Item   = NULL;\r
   Tmp    = NULL;\r
 \r
-  if ((DataSize == 0) && (DataSize % sizeof (EFI_IPv6_ADDRESS) != 0)) {\r
+  if ((DataSize != 0) && (DataSize % sizeof (EFI_IPv6_ADDRESS) != 0)) {\r
     return EFI_BAD_BUFFER_SIZE;\r
   }\r
 \r
@@ -1546,7 +1553,7 @@ Ip6ConfigSetDnsServer (
     }\r
   } else  {\r
     //\r
-    // DataSize is 0 and Data is NULL, clean up the DnsServer address. \r
+    // DataSize is 0 and Data is NULL, clean up the DnsServer address.\r
     //\r
     if (Item->Data.Ptr != NULL) {\r
       FreePool (Item->Data.Ptr);\r
@@ -1965,7 +1972,7 @@ Ip6ConfigOnDhcp6SbInstalled (
                                 network stack was set successfully.\r
   @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:\r
                                 - This is NULL.\r
-                                - One or more fields in Data and DataSizedo not match the \r
+                                - One or more fields in Data and DataSizedo not match the\r
                                   requirement of the data type indicated by DataType.\r
   @retval EFI_WRITE_PROTECTED   The specified configuration data is read-only or the specified\r
                                 configuration data cannot be set under the current policy.\r
@@ -2040,7 +2047,7 @@ EfiIp6ConfigSetData (
     }\r
   } else {\r
     //\r
-    // Another asynchornous process is on the way.\r
+    // Another asynchronous process is on the way.\r
     //\r
     Status = EFI_ACCESS_DENIED;\r
   }\r