pbrd: Prevent possible NULL use

the pnhi data structure can receive either a interface or a
nhr data structure.  Ensure that we don't crash.

CID -> 1500586
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2021-01-17 07:48:20 -05:00
parent 5c8ecf6e46
commit 920bb6f76a

View File

@ -770,18 +770,20 @@ pbr_nht_individual_nexthop_gw_update(struct pbr_nexthop_cache *pnhc,
goto done; goto done;
} }
switch (pnhi->nhr->prefix.family) { if (pnhi->nhr) {
case AF_INET: switch (pnhi->nhr->prefix.family) {
if (pnhc->nexthop.gate.ipv4.s_addr case AF_INET:
!= pnhi->nhr->prefix.u.prefix4.s_addr) if (pnhc->nexthop.gate.ipv4.s_addr
goto done; /* Unrelated change */ != pnhi->nhr->prefix.u.prefix4.s_addr)
break; goto done; /* Unrelated change */
case AF_INET6: break;
if (memcmp(&pnhc->nexthop.gate.ipv6, case AF_INET6:
&pnhi->nhr->prefix.u.prefix6, 16) if (memcmp(&pnhc->nexthop.gate.ipv6,
!= 0) &pnhi->nhr->prefix.u.prefix6, 16)
goto done; /* Unrelated change */ != 0)
break; goto done; /* Unrelated change */
break;
}
} }
pnhi->nhr_matched = true; pnhi->nhr_matched = true;