From 8ba7105057357c566a0475b32829241cca85d848 Mon Sep 17 00:00:00 2001 From: Nitin Soni Date: Tue, 29 Jan 2019 06:29:57 -0800 Subject: [PATCH] bgpd: fix valgrind flagged errors 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 Reviewed-by: CCR-8249 --- bgpd/bgp_debug.c | 2 ++ bgpd/bgp_evpn.c | 2 +- bgpd/bgp_route.c | 14 +++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index c7fad29cb0..39ba404f38 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -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)); diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index c74d7829bd..5a67cc4209 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -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, diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 07077dfe1f..804b035b87 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -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]); } -- 2.39.5