From: Martin Buck Date: Fri, 29 Jan 2021 18:26:49 +0000 (+0100) Subject: ospf6d: Fix LSA formatting inconsistent retvals X-Git-Tag: base_8.0~419^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=8e04b88b8db4b6c154686c0d43ca192f041072b8;p=matthieu%2Ffrr.git ospf6d: Fix LSA formatting inconsistent retvals Make return values for lh_get_prefix_str LSA handlers consistent, i.e. return NULL in case of error without having written to the passed buffer and non-NULL (address of buffer) if a string was written to the buffer. Previously, it was possible in certain cases (bogus LSAs) to not initialize (and 0-terminate) the buffer but still return non-NULL, causing the caller to print random junk. Signed-off-by: Martin Buck --- diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index 01e4b31c4e..fd154e7ee5 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -84,12 +84,13 @@ static char *ospf6_router_lsa_get_nbr_id(struct ospf6_lsa *lsa, char *buf, inet_ntop(AF_INET, &lsdesc->neighbor_router_id, buf2, sizeof(buf2)); sprintf(buf, "%s/%s", buf2, buf1); + + return buf; } - } else - return NULL; + } } - return buf; + return NULL; } static int ospf6_router_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, @@ -444,14 +445,15 @@ static char *ospf6_network_lsa_get_ar_id(struct ospf6_lsa *lsa, char *buf, if ((current + sizeof(struct ospf6_network_lsdesc)) <= end) { lsdesc = (struct ospf6_network_lsdesc *)current; - if (buf) + if (buf) { inet_ntop(AF_INET, &lsdesc->router_id, buf, buflen); - } else - return NULL; + return buf; + } + } } - return (buf); + return NULL; } static int ospf6_network_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, @@ -901,7 +903,7 @@ static char *ospf6_intra_prefix_lsa_get_prefix_str(struct ospf6_lsa *lsa, } } while (current <= end); } - return (buf); + return NULL; } static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,