From 0adb143f73b24d8cebf26c68cbed2d5b184addbf Mon Sep 17 00:00:00 2001 From: claudio Date: Fri, 28 Apr 2023 13:23:52 +0000 Subject: [PATCH] Add explicit default labels in switch() statements with error handling. Right now these are not reachable. Should also clear some gcc warnings. OK tb@ --- usr.sbin/bgpd/parse.y | 5 ++++- usr.sbin/bgpd/printconf.c | 17 ++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index 3ca06b539b1..b6a182040c1 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.453 2023/04/26 18:14:28 claudio Exp $ */ +/* $OpenBSD: parse.y,v 1.454 2023/04/28 13:23:52 claudio Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer @@ -5683,6 +5683,9 @@ push_prefix(struct bgpd_addr *addr, uint8_t len) complen = PREFIX_SIZE(len) + 1; data = &addr->v6; break; + default: + yyerror("unsupported address family for flowspec address"); + return -1; } comp = malloc(complen); if (comp == NULL) { diff --git a/usr.sbin/bgpd/printconf.c b/usr.sbin/bgpd/printconf.c index 75fa425e73d..32be9d82042 100644 --- a/usr.sbin/bgpd/printconf.c +++ b/usr.sbin/bgpd/printconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printconf.c,v 1.166 2023/04/21 10:48:33 claudio Exp $ */ +/* $OpenBSD: printconf.c,v 1.167 2023/04/28 13:23:52 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -542,12 +542,6 @@ print_flowspec_flags(struct flowspec *f, int type, int is_v6) const char *fmt, *flags; int complen, off = 0; - if (flowspec_get_component(f->data, f->len, type, is_v6, - &comp, &complen) != 1) - return; - - printf("%s ", flowspec_fmt_label(type)); - switch (type) { case FLOWSPEC_TYPE_TCP_FLAGS: flags = FLOWSPEC_TCP_FLAG_STRING; @@ -558,8 +552,17 @@ print_flowspec_flags(struct flowspec *f, int type, int is_v6) else flags = FLOWSPEC_FRAG_STRING6; break; + default: + printf("??? "); + return; } + if (flowspec_get_component(f->data, f->len, type, is_v6, + &comp, &complen) != 1) + return; + + printf("%s ", flowspec_fmt_label(type)); + fmt = flowspec_fmt_bin_op(comp, complen, &off, flags); if (off == -1) { printf("%s ", fmt); -- 2.20.1