From: Igor Ryzhov Date: Tue, 8 Feb 2022 17:31:34 +0000 (+0300) Subject: *: use ipaddr_cmp instead of memcmp X-Git-Tag: pim6-testing-20220430~345^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=60cda04dda2659b5bef684fe7b05ee0e501eb498;p=mirror%2Ffrr.git *: 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 --- diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c index 2254bc6ba7..d5046c4381 100644 --- a/bgpd/bgp_evpn_mh.c +++ b/bgpd/bgp_evpn_mh.c @@ -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) diff --git a/vrrpd/vrrp.c b/vrrpd/vrrp.c index 5c34c66df5..f91803337d 100644 --- a/vrrpd/vrrp.c +++ b/vrrpd/vrrp.c @@ -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); diff --git a/zebra/zebra_evpn_neigh.c b/zebra/zebra_evpn_neigh.c index 7299391ef6..c3218d0f9a 100644 --- a/zebra/zebra_evpn_neigh.c +++ b/zebra/zebra_evpn_neigh.c @@ -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)