MdeModulePkg/DxeNetLib: Add array range check in NetIp6IsNetEqual().

* The library API use array elements without any index range check, this
patch is to fix this issue to avoid null pointer reference.

V2
* Added an ASSERT check for the case PrefixLength equals to IP6_PREFIX_MAX.
* Synced some code descriptions to head file.

Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wang Fan <fan.wang@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
(cherry picked from commit e0e26f9c1f)
This commit is contained in:
Wang Fan
2018-01-11 18:09:24 +08:00
committed by Jiaxin Wu
parent 8d129948e9
commit e2cef60f80
2 changed files with 52 additions and 6 deletions

View File

@ -804,7 +804,7 @@ NetIp6IsLinkLocalAddr (
Check whether the Ipv6 address1 and address2 are on the connected network.
ASSERT if Ip1 or Ip2 is NULL.
ASSERT if PrefixLength exceeds IP6_PREFIX_MAX.
ASSERT if PrefixLength exceeds or equals to IP6_PREFIX_MAX.
@param[in] Ip1 - Ip6 address1, in network order.
@param[in] Ip2 - Ip6 address2, in network order.
@ -826,7 +826,7 @@ NetIp6IsNetEqual (
UINT8 Bit;
UINT8 Mask;
ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength <= IP6_PREFIX_MAX));
ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength < IP6_PREFIX_MAX));
if (PrefixLength == 0) {
return TRUE;
@ -842,6 +842,10 @@ NetIp6IsNetEqual (
if (Bit > 0) {
Mask = (UINT8) (0xFF << (8 - Bit));
ASSERT (Byte < 16);
if (Byte >= 16) {
return FALSE;
}
if ((Ip1->Addr[Byte] & Mask) != (Ip2->Addr[Byte] & Mask)) {
return FALSE;
}