]> git.puffer.fish Git - mirror/frr.git/commitdiff
*: use ipaddr_cmp instead of memcmp 10530/head
authorIgor Ryzhov <iryzhov@nfware.com>
Tue, 8 Feb 2022 17:31:34 +0000 (20:31 +0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Tue, 8 Feb 2022 17:31:34 +0000 (20:31 +0300)
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>
bgpd/bgp_evpn_mh.c
vrrpd/vrrp.c
zebra/zebra_evpn_neigh.c

index 2254bc6ba74df97aa92b75db306b033605629b11..d5046c438137227e2b82f22c96dbbb5a42cc7c0c 100644 (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)
index 5c34c66df5c6dff8e22ee8471197eb4885a557a5..f91803337d0569840db987c3471bf61cbceff159 100644 (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);
index 7299391ef6959203785ca6c28426af47f44bc280..c3218d0f9a6a2cc25d3c38f1d8a08b81a83cae53 100644 (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)