]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Config2Impl.c
index 131b03f7711beda89be489fd2941bd4663853162..f4dfbb6e31a730f0529eaaab6c4327aaf8a3a3c1 100644 (file)
@@ -609,6 +609,13 @@ Ip4Config2SetDefaultIf (
 \r
   IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r
 \r
+  //\r
+  // Check whether the StationAddress/SubnetMask pair is valid.\r
+  //\r
+  if (!Ip4StationAddressValid (StationAddress, SubnetMask)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   Status = Ip4Config2SetDefaultAddr (IpSb, StationAddress, SubnetMask);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -705,7 +712,6 @@ Ip4Config2SetDnsServerWorker (
 {\r
   UINTN                 OldIndex;\r
   UINTN                 NewIndex;\r
-  UINTN                 Index1;\r
   EFI_IPv4_ADDRESS      *OldDns;\r
   EFI_IPv4_ADDRESS      *NewDns;\r
   UINTN                 OldDnsCount;\r
@@ -747,15 +753,6 @@ Ip4Config2SetDnsServerWorker (
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    for (Index1 = NewIndex + 1; Index1 < NewDnsCount; Index1++) {\r
-      if (EFI_IP4_EQUAL (NewDns + NewIndex, NewDns + Index1)) {\r
-        if (Tmp != NULL) {\r
-          FreePool (Tmp);\r
-        }\r
-        return EFI_INVALID_PARAMETER;\r
-      }\r
-    }\r
-\r
     if (OneAdded) {\r
       //\r
       // If any address in the new setting is not in the old settings, skip the\r
@@ -1262,7 +1259,10 @@ Ip4Config2SetMaunualAddress (
   StationAddress = EFI_NTOHL (NewAddress.Address);\r
   SubnetMask = EFI_NTOHL (NewAddress.SubnetMask);\r
 \r
-  if (NetGetMaskLength (SubnetMask) == IP4_MASK_NUM) {\r
+  //\r
+  // Check whether the StationAddress/SubnetMask pair is valid.\r
+  //\r
+  if (!Ip4StationAddressValid (StationAddress, SubnetMask)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -1492,11 +1492,12 @@ Ip4Config2InitIfInfo (
   OUT EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo\r
   )\r
 {\r
-  IfInfo->Name[0] = L'e';\r
-  IfInfo->Name[1] = L't';\r
-  IfInfo->Name[2] = L'h';\r
-  IfInfo->Name[3] = (CHAR16) (L'0' + IpSb->Ip4Config2Instance.IfIndex);\r
-  IfInfo->Name[4] = 0;\r
+  UnicodeSPrint (\r
+    IfInfo->Name,\r
+    EFI_IP4_CONFIG2_INTERFACE_INFO_NAME_SIZE,\r
+    L"eth%d",\r
+    IpSb->Ip4Config2Instance.IfIndex\r
+  );\r
 \r
   IfInfo->IfType        = IpSb->SnpMode.IfType;\r
   IfInfo->HwAddressSize = IpSb->SnpMode.HwAddressSize;\r