diff options
author | Daniel Walton <dwalton@cumulusnetworks.com> | 2015-10-21 06:42:54 -0700 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2015-12-08 14:11:10 -0500 |
commit | 363c903435b154e989f0544d12d4ac8d50174c0b (patch) | |
tree | 3efcda7bc9e934ea17f2787a9f0ea9d59738ebea | |
parent | 92e62e06ba9e03c4603538b3138298b274e3c167 (diff) | |
download | quagga-363c903435b154e989f0544d12d4ac8d50174c0b.tar.bz2 quagga-363c903435b154e989f0544d12d4ac8d50174c0b.tar.xz |
bgpd: crash from not NULLing freed pointers
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
There was a crash from not NULLing out peer->hostname but I cleaned
up a bunch of other suspect ones as well.
-rw-r--r-- | bgpd/bgp_packet.c | 13 | ||||
-rw-r--r-- | bgpd/bgpd.c | 105 |
2 files changed, 87 insertions, 31 deletions
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index e1ae494d..4ab5b064 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -967,8 +967,13 @@ bgp_notify_send_with_data (struct peer *peer, u_char code, u_char sub_code, } } bgp_notify_print (peer, &bgp_notify, "sending"); + if (bgp_notify.data) - XFREE (MTYPE_TMP, bgp_notify.data); + { + XFREE (MTYPE_TMP, bgp_notify.data); + bgp_notify.data = NULL; + bgp_notify.length = 0; + } } if (BGP_DEBUG (normal, NORMAL)) @@ -1973,7 +1978,11 @@ bgp_notify_receive (struct peer *peer, bgp_size_t size) bgp_notify_print(peer, &bgp_notify, "received"); if (bgp_notify.data) - XFREE (MTYPE_TMP, bgp_notify.data); + { + XFREE (MTYPE_TMP, bgp_notify.data); + bgp_notify.data = NULL; + bgp_notify.length = 0; + } } /* peer count update */ diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index c7f22e8b..60428586 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -721,21 +721,36 @@ peer_free (struct peer *peer) BGP_EVENT_FLUSH (peer); if (peer->desc) - XFREE (MTYPE_PEER_DESC, peer->desc); + { + XFREE (MTYPE_PEER_DESC, peer->desc); + peer->desc = NULL; + } /* Free allocated host character. */ if (peer->host) - XFREE (MTYPE_BGP_PEER_HOST, peer->host); - + { + XFREE (MTYPE_BGP_PEER_HOST, peer->host); + peer->host = NULL; + } + /* Update source configuration. */ if (peer->update_source) - sockunion_free (peer->update_source); + { + sockunion_free (peer->update_source); + peer->update_source = NULL; + } if (peer->update_if) - XFREE (MTYPE_PEER_UPDATE_SOURCE, peer->update_if); + { + XFREE (MTYPE_PEER_UPDATE_SOURCE, peer->update_if); + peer->update_if = NULL; + } if (peer->clear_node_queue) - work_queue_free (peer->clear_node_queue); + { + work_queue_free(peer->clear_node_queue); + peer->clear_node_queue = NULL; + } if (peer->notify.data) XFREE(MTYPE_TMP, peer->notify.data); @@ -1266,22 +1281,41 @@ peer_delete (struct peer *peer) /* Buffers. */ if (peer->ibuf) - stream_free (peer->ibuf); + { + stream_free (peer->ibuf); + peer->ibuf = NULL; + } + if (peer->obuf) - stream_fifo_free (peer->obuf); + { + stream_fifo_free (peer->obuf); + peer->obuf = NULL; + } + if (peer->work) - stream_free (peer->work); + { + stream_free (peer->work); + peer->work = NULL; + } + if (peer->scratch) - stream_free(peer->scratch); - peer->obuf = NULL; - peer->work = peer->scratch = peer->ibuf = NULL; + { + stream_free(peer->scratch); + peer->scratch = NULL; + } /* Local and remote addresses. */ if (peer->su_local) - sockunion_free (peer->su_local); + { + sockunion_free (peer->su_local); + peer->su_local = NULL; + } + if (peer->su_remote) - sockunion_free (peer->su_remote); - peer->su_local = peer->su_remote = NULL; + { + sockunion_free (peer->su_remote); + peer->su_remote = NULL; + } /* Free filter related memory. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) @@ -1292,31 +1326,44 @@ peer_delete (struct peer *peer) for (i = FILTER_IN; i < FILTER_MAX; i++) { if (filter->dlist[i].name) - free (filter->dlist[i].name); + { + free(filter->dlist[i].name); + filter->dlist[i].name = NULL; + } + if (filter->plist[i].name) - free (filter->plist[i].name); + { + free(filter->plist[i].name); + filter->plist[i].name = NULL; + } + if (filter->aslist[i].name) - free (filter->aslist[i].name); - - filter->dlist[i].name = NULL; - filter->plist[i].name = NULL; - filter->aslist[i].name = NULL; + { + free(filter->aslist[i].name); + filter->aslist[i].name = NULL; + } } + for (i = RMAP_IN; i < RMAP_MAX; i++) { if (filter->map[i].name) - free (filter->map[i].name); - filter->map[i].name = NULL; + { + free (filter->map[i].name); + filter->map[i].name = NULL; + } } if (filter->usmap.name) - free (filter->usmap.name); + { + free (filter->usmap.name); + filter->usmap.name = NULL; + } if (peer->default_rmap[afi][safi].name) - free (peer->default_rmap[afi][safi].name); - - filter->usmap.name = NULL; - peer->default_rmap[afi][safi].name = NULL; + { + free (peer->default_rmap[afi][safi].name); + peer->default_rmap[afi][safi].name = NULL; + } } peer_unlock (peer); /* initial reference */ |