]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: fix valgrind flagged errors 3692/head
authorNitin Soni <nsoni@cumulusnetworks.com>
Tue, 29 Jan 2019 14:29:57 +0000 (06:29 -0800)
committerNitin Soni <nsoni@cumulusnetworks.com>
Tue, 29 Jan 2019 14:29:57 +0000 (06:29 -0800)
Executed some evpn related tests with valgrind and saw some errors
related to uninitialized memory and overlapping memcpy. This commit
fixes those.

Ticket: CM-21218
Signed-off-by: Nitin Soni <nsoni@cumulusnetworks.com>
Reviewed-by: CCR-8249
bgpd/bgp_debug.c
bgpd/bgp_evpn.c
bgpd/bgp_route.c

index c7fad29cb02f85e3f330b00e99aa0c6b8b3a8889..39ba404f384eebe2c70c81d29de33546161e303d 100644 (file)
@@ -368,6 +368,8 @@ int bgp_dump_attr(struct attr *attr, char *buf, size_t size)
        if (!attr)
                return 0;
 
+       buf[0] = '\0';
+
        if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)))
                snprintf(buf, size, "nexthop %s", inet_ntoa(attr->nexthop));
 
index c74d7829bd527f620c5289281b3b89e566d7dda4..5a67cc4209a3d029a5dfbe6e59a6e1d3cc508a3f 100644 (file)
@@ -5279,7 +5279,7 @@ int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp)
 
                                if (bgp_nexthop_self(bgp, pi->attr->nexthop)) {
 
-                                       char attr_str[BUFSIZ];
+                                       char attr_str[BUFSIZ] = {0};
                                        char pbuf[PREFIX_STRLEN];
 
                                        bgp_dump_attr(pi->attr, attr_str,
index 07077dfe1f035c3986227e26c5815834115ebd77..804b035b87eb594cace4ab496c7f4db136be8ded 100644 (file)
@@ -3245,9 +3245,11 @@ int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id,
                /* Update MPLS label */
                if (has_valid_label) {
                        extra = bgp_path_info_extra_get(pi);
-                       memcpy(&extra->label, label,
-                              num_labels * sizeof(mpls_label_t));
-                       extra->num_labels = num_labels;
+                       if (extra->label != label) {
+                               memcpy(&extra->label, label,
+                                               num_labels * sizeof(mpls_label_t));
+                               extra->num_labels = num_labels;
+                       }
                        if (!(afi == AFI_L2VPN && safi == SAFI_EVPN))
                                bgp_set_valid_label(&extra->label[0]);
                }
@@ -3416,8 +3418,10 @@ int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id,
        /* Update MPLS label */
        if (has_valid_label) {
                extra = bgp_path_info_extra_get(new);
-               memcpy(&extra->label, label, num_labels * sizeof(mpls_label_t));
-               extra->num_labels = num_labels;
+               if (extra->label != label) {
+                       memcpy(&extra->label, label, num_labels * sizeof(mpls_label_t));
+                       extra->num_labels = num_labels;
+               }
                if (!(afi == AFI_L2VPN && safi == SAFI_EVPN))
                        bgp_set_valid_label(&extra->label[0]);
        }