]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: fix memory leak when parsing capabilities
authorQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 15 Jan 2020 18:00:34 +0000 (13:00 -0500)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 15 Jan 2020 18:18:10 +0000 (13:18 -0500)
Duplicated domain name capability messages cause memory leak. The amount
of leaked memory is proportional to the size of the duplicated
capabilities. This bug was introduced in 2015.

To hit this, a BGP OPEN message must contain multiple FQDN capabilities.
Memory is leaked when the hostname portion of the capability is of
length 0, but the domainname portion is not, for any of the duplicated
capabilities beyond the first one.

https://tools.ietf.org/html/draft-walton-bgp-hostname-capability-00

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
bgpd/bgp_open.c

index 7e5e07099d00022bc94c42bff2af6d7a7500b599..d39d1f7a2d18d487bbbcb4d62ffebb09af9459f4 100644 (file)
@@ -747,6 +747,12 @@ static int bgp_capability_hostname(struct peer *peer,
 
        if (len) {
                str[len] = '\0';
+
+               if (peer->domainname != NULL) {
+                       XFREE(MTYPE_BGP_PEER_HOST, peer->domainname);
+                       peer->domainname = NULL;
+               }
+
                peer->domainname = XSTRDUP(MTYPE_BGP_PEER_HOST, str);
        }