*: use ipaddr_cmp instead of memcmp

Using memcmp is wrong because struct ipaddr may contain unitialized
padding bytes that should not be compared.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
Igor Ryzhov 2022-02-08 20:31:34 +03:00
parent 107f77b56f
commit 60cda04dda
3 changed files with 6 additions and 6 deletions

View File

@ -4306,7 +4306,7 @@ static bool bgp_evpn_nh_cmp(const void *p1, const void *p2)
if (n1 == NULL || n2 == NULL)
return false;
return (memcmp(&n1->ip, &n2->ip, sizeof(struct ipaddr)) == 0);
return (ipaddr_cmp(&n1->ip, &n2->ip) == 0);
}
void bgp_evpn_nh_init(struct bgp *bgp_vrf)

View File

@ -405,7 +405,7 @@ static bool vrrp_has_ip(struct vrrp_vrouter *vr, struct ipaddr *ip)
struct ipaddr *iter;
for (ALL_LIST_ELEMENTS_RO(r->addrs, ln, iter))
if (!memcmp(&iter->ip, &ip->ip, IPADDRSZ(ip)))
if (!ipaddr_cmp(iter, ip))
return true;
return false;
@ -484,7 +484,7 @@ int vrrp_del_ip(struct vrrp_vrouter *vr, struct ipaddr *ip)
return 0;
for (ALL_LIST_ELEMENTS(r->addrs, ln, nn, iter))
if (!memcmp(&iter->ip, &ip->ip, IPADDRSZ(ip)))
if (!ipaddr_cmp(iter, ip))
list_delete_node(r->addrs, ln);
/*
@ -903,7 +903,7 @@ static int vrrp_recv_advertisement(struct vrrp_router *r, struct ipaddr *src,
switch (r->fsm.state) {
case VRRP_STATE_MASTER:
addrcmp = memcmp(&src->ip, &r->src.ip, IPADDRSZ(src));
addrcmp = ipaddr_cmp(src, &r->src);
if (pkt->hdr.priority == 0) {
vrrp_send_advertisement(r);

View File

@ -72,7 +72,7 @@ static bool neigh_cmp(const void *p1, const void *p2)
if (n1 == NULL || n2 == NULL)
return false;
return (memcmp(&n1->ip, &n2->ip, sizeof(struct ipaddr)) == 0);
return ipaddr_cmp(&n1->ip, &n2->ip) == 0;
}
int neigh_list_cmp(void *p1, void *p2)
@ -80,7 +80,7 @@ int neigh_list_cmp(void *p1, void *p2)
const struct zebra_neigh *n1 = p1;
const struct zebra_neigh *n2 = p2;
return memcmp(&n1->ip, &n2->ip, sizeof(struct ipaddr));
return ipaddr_cmp(&n1->ip, &n2->ip);
}
struct hash *zebra_neigh_db_create(const char *desc)