From: Igor Ryzhov Date: Wed, 9 Feb 2022 21:14:39 +0000 (+0300) Subject: bgpd: fix null pointer dereferences X-Git-Tag: pim6-testing-20220430~337^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=cfe4dce98b1880ecf4894d527d0326907dab756d;p=mirror%2Ffrr.git bgpd: fix null pointer dereferences They were introduced during recent ecommunity rework in b53e67a3. CID 1511347 and 1511348. Signed-off-by: Igor Ryzhov --- diff --git a/bgpd/bgp_attr_evpn.c b/bgpd/bgp_attr_evpn.c index 09b71e5d64..e528fadedd 100644 --- a/bgpd/bgp_attr_evpn.c +++ b/bgpd/bgp_attr_evpn.c @@ -53,8 +53,10 @@ void bgp_add_routermac_ecom(struct attr *attr, struct ethaddr *routermac) routermac_ecom.val[0] = ECOMMUNITY_ENCODE_EVPN; routermac_ecom.val[1] = ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC; memcpy(&routermac_ecom.val[2], routermac->octet, ETH_ALEN); - if (!ecomm) + if (!ecomm) { bgp_attr_set_ecommunity(attr, ecommunity_new()); + ecomm = bgp_attr_get_ecommunity(attr); + } ecommunity_add_val(ecomm, &routermac_ecom, false, false); ecommunity_str(ecomm); } diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index 6c08168cf6..174fadc23e 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -467,7 +467,7 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr) struct transit *transit; struct cluster_list *cluster; char buf[BUFSIZ]; - struct ecommunity *ecomm = bgp_attr_get_ecommunity(attr); + struct ecommunity *ecomm; if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) return; @@ -485,6 +485,7 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr) fp(out, " community=%p, refcnt=%d%s", attr->community, (attr->community ? attr->community->refcnt : 0), HVTYNL); + ecomm = bgp_attr_get_ecommunity(attr); fp(out, " ecommunity=%p, refcnt=%d%s", ecomm, (ecomm ? ecomm->refcnt : 0), HVTYNL);