]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Ip4Dxe: Add wrong/invalid subnet check
authorJiaxin Wu <jiaxin.wu@intel.com>
Fri, 11 Nov 2016 04:47:01 +0000 (12:47 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Thu, 17 Nov 2016 00:21:13 +0000 (08:21 +0800)
v2:
* Separate out the return status fix.
* Replace IP4_MASK_MAX with IP4_MASK_NUM.
* Remove the ON_EXIT label.

This patch is used to add the wrong/invalid subnet check.

Cc: Santhapur Naveen <naveens@amiindia.co.in>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c

index a931bb3e77286fce85334fe0e9647263c0cdd50c..5b01b35b760e71c59d43625c1b4b9e779410df2e 100644 (file)
@@ -1255,6 +1255,13 @@ Ip4Config2SetMaunualAddress (
 \r
   NewAddress = *((EFI_IP4_CONFIG2_MANUAL_ADDRESS *) Data);\r
 \r
+  StationAddress = EFI_NTOHL (NewAddress.Address);\r
+  SubnetMask = EFI_NTOHL (NewAddress.SubnetMask);\r
+\r
+  if (NetGetMaskLength (SubnetMask) == IP4_MASK_NUM) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   //\r
   // Store the new data, and init the DataItem status to EFI_NOT_READY because\r
   // we may have an asynchronous configuration process.\r
@@ -1273,9 +1280,6 @@ Ip4Config2SetMaunualAddress (
   DataItem->DataSize = DataSize;\r
   DataItem->Status   = EFI_NOT_READY;\r
 \r
-  StationAddress = EFI_NTOHL (NewAddress.Address);\r
-  SubnetMask = EFI_NTOHL (NewAddress.SubnetMask);\r
-\r
   IpSb->Reconfig = TRUE;\r
   Status = Ip4Config2SetDefaultAddr (IpSb, StationAddress, SubnetMask);\r
   if (EFI_ERROR (Status)) {\r
index 9cd5dd547ab2303b8a690a355ee3b4d03f0e7726..b0cc6a3dc7f0bd3ca343d77c033aafc2cd23211c 100644 (file)
@@ -564,6 +564,11 @@ Ip4SetAddress (
 \r
   NET_CHECK_SIGNATURE (Interface, IP4_INTERFACE_SIGNATURE);\r
 \r
+  Len = NetGetMaskLength (SubnetMask);\r
+  if (Len == IP4_MASK_NUM) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   //\r
   // Set the ip/netmask, then compute the subnet broadcast\r
   // and network broadcast for easy access. When computing\r
@@ -575,9 +580,6 @@ Ip4SetAddress (
   Interface->Ip             = IpAddr;\r
   Interface->SubnetMask     = SubnetMask;\r
   Interface->SubnetBrdcast  = (IpAddr | ~SubnetMask);\r
-\r
-  Len                       = NetGetMaskLength (SubnetMask);\r
-  ASSERT (Len <= IP4_MASK_MAX);\r
   Interface->NetBrdcast     = (IpAddr | ~SubnetMask);\r
 \r
   //\r