On Mon, Apr 17, 2023 at 02:30:40PM +0200, Claudio Jeker wrote:
> Forgot this bit in the 'bgpctl show rib 192.0.2.1 detail' support I
> commited this weekend.
> 
> The problem is that parse_prefix() is entered with 'detail' as argument
> and clears the previously set address. So be more careful and only modify
> the addr pointer if parse_prefix() and parse_addr() are successful.

Ugh, sorry for missing this.

ok tb

> 
> -- 
> :wq Claudio
> 
> Index: parser.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/bgpctl/parser.c,v
> retrieving revision 1.127
> diff -u -p -r1.127 parser.c
> --- parser.c  17 Apr 2023 11:02:40 -0000      1.127
> +++ parser.c  17 Apr 2023 12:29:29 -0000
> @@ -876,10 +876,10 @@ parse_addr(const char *word, struct bgpd
>       if (word == NULL)
>               return (0);
>  
> -     memset(addr, 0, sizeof(struct bgpd_addr));
>       memset(&ina, 0, sizeof(ina));
>  
>       if (inet_net_pton(AF_INET, word, &ina, sizeof(ina)) != -1) {
> +             memset(addr, 0, sizeof(*addr));
>               addr->aid = AID_INET;
>               addr->v4 = ina;
>               return (1);
> @@ -902,6 +902,7 @@ int
>  parse_prefix(const char *word, size_t wordlen, struct bgpd_addr *addr,
>      uint8_t *prefixlen)
>  {
> +     struct bgpd_addr tmp;
>       char            *p, *ps;
>       const char      *errstr;
>       int              mask = -1;
> @@ -909,7 +910,7 @@ parse_prefix(const char *word, size_t wo
>       if (word == NULL)
>               return (0);
>  
> -     memset(addr, 0, sizeof(struct bgpd_addr));
> +     memset(&tmp, 0, sizeof(tmp));
>  
>       if ((p = strrchr(word, '/')) != NULL) {
>               size_t plen = strlen(p);
> @@ -921,17 +922,17 @@ parse_prefix(const char *word, size_t wo
>                       err(1, "parse_prefix: malloc");
>               strlcpy(ps, word, wordlen - plen + 1);
>  
> -             if (parse_addr(ps, addr) == 0) {
> +             if (parse_addr(ps, &tmp) == 0) {
>                       free(ps);
>                       return (0);
>               }
>  
>               free(ps);
>       } else
> -             if (parse_addr(word, addr) == 0)
> +             if (parse_addr(word, &tmp) == 0)
>                       return (0);
>  
> -     switch (addr->aid) {
> +     switch (tmp.aid) {
>       case AID_INET:
>               if (mask == -1)
>                       mask = 32;
> @@ -946,7 +947,7 @@ parse_prefix(const char *word, size_t wo
>               return (0);
>       }
>  
> -     applymask(addr, addr, mask);
> +     applymask(addr, &tmp, mask);
>       *prefixlen = mask;
>       return (1);
>  }
> 

Reply via email to