From e0b5ca875b0b48ef8785633c850be21a92a9b2a5 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Mon, 1 Mar 2021 08:51:13 -0500 Subject: [PATCH] lib: print NULL for NULL nexthops Instead of crashing, print "NULL" when printfrr callback for nexthops is called for a NULL nexthop argument. Signed-off-by: Mark Stapp --- lib/nexthop.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/nexthop.c b/lib/nexthop.c index b2fa945690..dd8c108205 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -739,6 +739,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') { -- 2.39.5