From daf9ddbbc6aba72be892dd1a1c29779f9a8cb85e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 1 Mar 2017 07:47:37 -0500 Subject: [PATCH] bgpd: Cleanup grabbag of coverity scan issues found Signed-off-by: Donald Sharp --- bgpd/bgp_clist.c | 10 +++++++--- bgpd/bgp_encap.c | 13 ++++++++----- bgpd/bgp_evpn.c | 2 +- bgpd/bgp_vty.c | 4 ++++ bgpd/bgpd.c | 4 ++-- bgpd/rfapi/vnc_zebra.c | 2 ++ 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c index 637c95fa7c..3def97c73d 100644 --- a/bgpd/bgp_clist.c +++ b/bgpd/bgp_clist.c @@ -506,18 +506,22 @@ lcommunity_str_get (struct lcommunity *lcom, int i) static int lcommunity_regexp_include (regex_t * reg, struct lcommunity *lcom, int i) { - const char *str; + char *str; /* When there is no communities attribute it is treated as empty string. */ if (lcom == NULL || lcom->size == 0) - str = ""; + str = XSTRDUP (MTYPE_LCOMMUNITY_STR, ""); else str = lcommunity_str_get (lcom, i); /* Regular expression match. */ if (regexec (reg, str, 0, NULL, 0) == 0) - return 1; + { + XFREE (MTYPE_LCOMMUNITY_STR, str); + return 1; + } + XFREE (MTYPE_LCOMMUNITY_STR, str); /* No match. */ return 0; } diff --git a/bgpd/bgp_encap.c b/bgpd/bgp_encap.c index 6e021c4e9e..603979942d 100644 --- a/bgpd/bgp_encap.c +++ b/bgpd/bgp_encap.c @@ -589,24 +589,27 @@ DEFUN (show_bgp_ipv4_encap_neighbor_routes, "Neighbor to display information about\n" "Display routes learned from neighbor\n") { - int idx_peer = 5; - union sockunion su; + int idx_peer = 0; + union sockunion *su; struct peer *peer; - if (sockunion_str2su (argv[idx_peer]->arg)) + argv_find(argv, argc, "A.B.C.D", &idx_peer); + su = sockunion_str2su (argv[idx_peer]->arg); + + if (!su) { vty_out (vty, "Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE); return CMD_WARNING; } - peer = peer_lookup (NULL, &su); + peer = peer_lookup (NULL, su); if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP]) { vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); return CMD_WARNING; } - return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_neighbor, &su, 0); + return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_neighbor, su, 0); } DEFUN (show_bgp_ipv6_encap_neighbor_routes, diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index b9acbbed08..1ab8e23236 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -125,7 +125,7 @@ bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr, if (route_length - 4 - 10 - 8 - 3 /* label to be read */ >= 32) { p_evpn_p->flags = IP_PREFIX_V6; - memcpy(&(p_evpn_p->ip.v4_addr), pnt, 16); + memcpy(&(p_evpn_p->ip.v6_addr), pnt, 16); pnt += 16; memcpy(&evpn.gw_ip.ipv6, pnt, 16); pnt += 16; diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index aa8c3145f9..6ad356a04c 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -11093,6 +11093,8 @@ DEFUN (no_ip_community_list_standard_all, int ret = community_list_unset (bgp_clist, cl_name_or_number, str, direct, style, delete_all); + XFREE (MTYPE_TMP, str); + if (ret < 0) { community_list_perror (vty, ret); @@ -11170,6 +11172,8 @@ DEFUN (no_ip_community_list_expanded_all, int ret = community_list_unset (bgp_clist, cl_name_or_number, str, direct, style, delete_all); + XFREE (MTYPE_TMP, str); + if (ret < 0) { community_list_perror (vty, ret); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 3512167b02..42a0f8d4b8 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -2524,7 +2524,7 @@ peer_group_delete (struct peer_group *group) list_delete (group->listen_range[afi]); } - XFREE(MTYPE_BGP_PEER_HOST, group->name); + XFREE(MTYPE_PEER_GROUP_HOST, group->name); group->name = NULL; group->conf->group = NULL; @@ -5458,7 +5458,7 @@ peer_prefix_list_unset (struct peer *peer, afi_t afi, safi_t safi, int direct) if (gfilter->plist[direct].name) { if (filter->plist[direct].name) - XSTRDUP(MTYPE_BGP_FILTER_NAME, filter->plist[direct].name); + XFREE(MTYPE_BGP_FILTER_NAME, filter->plist[direct].name); filter->plist[direct].name = XSTRDUP(MTYPE_BGP_FILTER_NAME, gfilter->plist[direct].name); filter->plist[direct].plist = gfilter->plist[direct].plist; peer_on_policy_change(peer, afi, safi, diff --git a/bgpd/rfapi/vnc_zebra.c b/bgpd/rfapi/vnc_zebra.c index 23b6e9dbb4..84b299ce1d 100644 --- a/bgpd/rfapi/vnc_zebra.c +++ b/bgpd/rfapi/vnc_zebra.c @@ -547,6 +547,7 @@ vnc_zebra_route_msg ( api.nexthop = nhp_ary; api.ifindex_num = 0; api.instance = 0; + api.safi = SAFI_UNICAST; if (BGP_DEBUG (zebra, ZEBRA)) { @@ -582,6 +583,7 @@ vnc_zebra_route_msg ( api.ifindex_num = 1; api.ifindex = &ifindex; api.instance = 0; + api.safi = SAFI_UNICAST; if (BGP_DEBUG (zebra, ZEBRA)) { -- 2.39.5