From cbb65f5ef53d9029811e248608125ffa293753eb Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 23 Oct 2017 19:19:26 -0200 Subject: [PATCH] *: fix coverity warnings - error handling issues Ignore the return value of some functions in the places we know they can't fail, and other small fixes. Regarding the change in bgpd/rfapi/rfapi_rib.c, asserting that rfapiRaddr2Qprefix() didn't fail is the common idiom inside the rfapi code. Signed-off-by: Renato Westphal --- bgpd/bgp_evpn.c | 2 +- bgpd/bgp_route.c | 2 +- bgpd/bgp_updgrp_adv.c | 15 +++++++-------- bgpd/bgp_updgrp_packet.c | 14 ++++++-------- bgpd/rfapi/rfapi_rib.c | 2 +- eigrpd/eigrp_vty.c | 4 ++-- vtysh/vtysh_main.c | 2 +- 7 files changed, 19 insertions(+), 22 deletions(-) diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index a09d966d7b..182a6c64f2 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -2542,7 +2542,7 @@ void bgp_evpn_derive_auto_rd(struct bgp *bgp, struct bgpevpn *vpn) vpn->prd.family = AF_UNSPEC; vpn->prd.prefixlen = 64; sprintf(buf, "%s:%hu", inet_ntoa(bgp->router_id), vpn->rd_id); - str2prefix_rd(buf, &vpn->prd); + (void)str2prefix_rd(buf, &vpn->prd); UNSET_FLAG(vpn->flags, VNI_FLAG_RD_CFGD); } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 0c2a2f6fe9..af71088b7d 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -10545,7 +10545,7 @@ DEFUN (show_bgp_afi_vpn_rd_route, afi_t afi = AFI_MAX; int idx = 0; - argv_find_and_parse_afi(argv, argc, &idx, &afi); + (void)argv_find_and_parse_afi(argv, argc, &idx, &afi); ret = str2prefix_rd(argv[5]->arg, &prd); if (!ret) { vty_out(vty, "%% Malformed Route Distinguisher\n"); diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c index fbbeaee9b2..8a24cba598 100644 --- a/bgpd/bgp_updgrp_adv.c +++ b/bgpd/bgp_updgrp_adv.c @@ -687,11 +687,11 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw) attr.local_pref = bgp->default_local_pref; - if (afi == AFI_IP) - str2prefix("0.0.0.0/0", &p); - else if (afi == AFI_IP6) { - str2prefix("::/0", &p); + memset(&p, 0, sizeof(p)); + p.family = afi2family(afi); + p.prefixlen = 0; + if (afi == AFI_IP6) { /* IPv6 global nexthop must be included. */ attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL; @@ -759,10 +759,9 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw) * clear adj_out for the 0.0.0.0/0 prefix in the BGP * table. */ - if (afi == AFI_IP) - str2prefix("0.0.0.0/0", &p); - else - str2prefix("::/0", &p); + memset(&p, 0, sizeof(p)); + p.family = afi2family(afi); + p.prefixlen = 0; rn = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, &p, NULL); diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index 433c5ce512..a35d814e47 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -1090,10 +1090,9 @@ void subgroup_default_update_packet(struct update_subgroup *subgrp, bpacket_attr_vec_arr_reset(&vecarr); addpath_encode = bgp_addpath_encode_tx(peer, afi, safi); - if (afi == AFI_IP) - str2prefix("0.0.0.0/0", &p); - else - str2prefix("::/0", &p); + memset(&p, 0, sizeof(p)); + p.family = afi2family(afi); + p.prefixlen = 0; /* Logging the attribute. */ if (bgp_debug_update(NULL, &p, subgrp->update_group, 0)) { @@ -1176,10 +1175,9 @@ void subgroup_default_withdraw_packet(struct update_subgroup *subgrp) safi = SUBGRP_SAFI(subgrp); addpath_encode = bgp_addpath_encode_tx(peer, afi, safi); - if (afi == AFI_IP) - str2prefix("0.0.0.0/0", &p); - else - str2prefix("::/0", &p); + memset(&p, 0, sizeof(p)); + p.family = afi2family(afi); + p.prefixlen = 0; if (bgp_debug_update(NULL, &p, subgrp->update_group, 0)) { char buf[PREFIX_STRLEN]; diff --git a/bgpd/rfapi/rfapi_rib.c b/bgpd/rfapi/rfapi_rib.c index 92cd1888ee..36ae6e7273 100644 --- a/bgpd/rfapi/rfapi_rib.c +++ b/bgpd/rfapi/rfapi_rib.c @@ -1668,7 +1668,7 @@ void rfapiRibUpdatePendingNode( struct prefix pfx_vn; - rfapiRaddr2Qprefix(&rfd->vn_addr, &pfx_vn); + assert(!rfapiRaddr2Qprefix(&rfd->vn_addr, &pfx_vn)); if (prefix_same(&pfx_vn, &pfx_nh)) continue; } diff --git a/eigrpd/eigrp_vty.c b/eigrpd/eigrp_vty.c index 5fc7818166..4e76428535 100644 --- a/eigrpd/eigrp_vty.c +++ b/eigrpd/eigrp_vty.c @@ -398,7 +398,7 @@ DEFUN (eigrp_network, struct prefix p; int ret; - str2prefix(argv[1]->arg, &p); + (void)str2prefix(argv[1]->arg, &p); ret = eigrp_network_set(eigrp, &p); @@ -421,7 +421,7 @@ DEFUN (no_eigrp_network, struct prefix p; int ret; - str2prefix(argv[2]->arg, &p); + (void)str2prefix(argv[2]->arg, &p); ret = eigrp_network_unset(eigrp, &p); diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index 8509a8a05a..57042f8e62 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -533,7 +533,7 @@ int main(int argc, char **argv, char **env) fp = open(history_file, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); - if (fp) + if (fp != -1) close(fp); read_history(history_file); -- 2.39.5