diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c
index 3c29f75f88..a843150f46 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c
@@ -581,9 +581,10 @@ Ip4SetAddress (
   Interface->SubnetBrdcast  = (IpAddr | ~SubnetMask);
 
   Type                      = NetGetIpClass (IpAddr);
+  ASSERT (Type <= IP4_ADDR_CLASSC);
   Len                       = NetGetMaskLength (SubnetMask);
-  ASSERT (Len >= 1);
-  Netmask                   = gIp4AllMasks[MIN ((Len - 1), Type << 3)];
+  ASSERT (Len < IP4_MASK_NUM);
+  Netmask                   = gIp4AllMasks[MIN (Len, Type << 3)];
   Interface->NetBrdcast     = (IpAddr | ~Netmask);
 
   //