From eb14a71d0632ab6a5d997892dcdee3682a0a7149 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 0ea72d03e1..facb83f6d5 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -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') { -- 2.39.5