[quagga-dev,15556,05/16] bgpd: don't leak memory in community_regexp_include

Message ID 1465927630-27768-5-git-send-email-chris@opensourcerouting.org
State Under Review
Headers show
Series
  • [quagga-dev,15552,01/16] zebra: fix null pointer dereference in zsend_ipv4_nexthop_lookup_mrib
Related show

Commit Message

Christian Franke June 14, 2016, 6:06 p.m.
From: Christian Franke <nobody@nowhere.ws>

Signed-off-by: Christian Franke <chris@opensourcerouting.org>
---
 bgpd/bgp_clist.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Donald Sharp June 15, 2016, 12:34 p.m. | #1
Acked-by: Donald Sharp <sharpd@cumulusnetworks.com>

On Tue, Jun 14, 2016 at 2:06 PM, Christian Franke <
chris@opensourcerouting.org> wrote:

> From: Christian Franke <nobody@nowhere.ws>
>
> Signed-off-by: Christian Franke <chris@opensourcerouting.org>
> ---
>  bgpd/bgp_clist.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c
> index 1f1a4e7..800bd01 100644
> --- a/bgpd/bgp_clist.c
> +++ b/bgpd/bgp_clist.c
> @@ -402,17 +402,22 @@ community_str_get (struct community *com, int i)
>  static int
>  community_regexp_include (regex_t * reg, struct community *com, int i)
>  {
> -  const char *str;
> +  char *str;
> +  int rv;
>
>    /* When there is no communities attribute it is treated as empty
>   *      string.  */
>    if (com == NULL || com->size == 0)
> -    str = "";
> +    str = XSTRDUP(MTYPE_COMMUNITY_STR, "");
>    else
>      str = community_str_get (com, i);
>
>    /* Regular expression match.  */
> -  if (regexec (reg, str, 0, NULL, 0) == 0)
> +  rv = regexec (reg, str, 0, NULL, 0);
> +
> +  XFREE(MTYPE_COMMUNITY_STR, str);
> +
> +  if (rv == 0)
>      return 1;
>
>    /* No match.  */
> --
> 2.8.0
>
>
> _______________________________________________
> Quagga-dev mailing list
> Quagga-dev@lists.quagga.net
> https://lists.quagga.net/mailman/listinfo/quagga-dev
>

Patch hide | download patch | download mbox

diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c
index 1f1a4e7..800bd01 100644
--- a/bgpd/bgp_clist.c
+++ b/bgpd/bgp_clist.c
@@ -402,17 +402,22 @@  community_str_get (struct community *com, int i)
 static int
 community_regexp_include (regex_t * reg, struct community *com, int i)
 {
-  const char *str;
+  char *str;
+  int rv;
 
   /* When there is no communities attribute it is treated as empty
  *      string.  */
   if (com == NULL || com->size == 0)
-    str = "";
+    str = XSTRDUP(MTYPE_COMMUNITY_STR, "");
   else
     str = community_str_get (com, i);
 
   /* Regular expression match.  */
-  if (regexec (reg, str, 0, NULL, 0) == 0)
+  rv = regexec (reg, str, 0, NULL, 0);
+
+  XFREE(MTYPE_COMMUNITY_STR, str);
+
+  if (rv == 0)
     return 1;
 
   /* No match.  */