]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: print NULL for NULL nexthops
authorMark Stapp <mjs@voltanet.io>
Mon, 1 Mar 2021 13:51:13 +0000 (08:51 -0500)
committerIgor Ryzhov <iryzhov@nfware.com>
Wed, 24 Mar 2021 12:09:02 +0000 (15:09 +0300)
Instead of crashing, print "NULL" when printfrr callback for
nexthops is called for a NULL nexthop argument.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
lib/nexthop.c

index 0ea72d03e16a857e2c8f0c32bb2ff4c4860ad92b..facb83f6d50bb1e17aa392beabf225bafd7b3269 100644 (file)
@@ -776,6 +776,16 @@ static ssize_t printfrr_nh(char *buf, size_t bsz, const char *fmt,
        const char *s, *v_is = "", *v_via = "", *v_viaif = "via ";
        ssize_t ret = 3;
 
+       /* NULL-check */
+       if (nexthop == NULL) {
+               if (fmt[2] == 'v' && fmt[3] == 'v')
+                       ret++;
+
+               strlcpy(buf, "NULL", bsz);
+
+               return ret;
+       }
+
        switch (fmt[2]) {
        case 'v':
                if (fmt[3] == 'v') {