From c39008533c9c03f2c7e55e40811337079d7b67aa Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Thu, 18 Apr 2019 10:17:57 +0300 Subject: [PATCH] bgpd: Validate as-path in `show bgp regexp` Signed-off-by: Donatas Abraitis --- bgpd/bgp_filter.c | 2 +- bgpd/bgp_filter.h | 1 + bgpd/bgp_route.c | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bgpd/bgp_filter.c b/bgpd/bgp_filter.c index a788ea68f3..b262f6b56d 100644 --- a/bgpd/bgp_filter.c +++ b/bgpd/bgp_filter.c @@ -389,7 +389,7 @@ static int as_list_dup_check(struct as_list *aslist, struct as_filter *new) return 0; } -static int config_bgp_aspath_validate(const char *regstr) +int config_bgp_aspath_validate(const char *regstr) { char valid_chars[] = "1234567890_^|[,{}() ]$*+.?-\\"; diff --git a/bgpd/bgp_filter.h b/bgpd/bgp_filter.h index e54372f8e0..3c49e357ff 100644 --- a/bgpd/bgp_filter.h +++ b/bgpd/bgp_filter.h @@ -31,5 +31,6 @@ extern enum as_filter_type as_list_apply(struct as_list *, void *); extern struct as_list *as_list_lookup(const char *); extern void as_list_add_hook(void (*func)(char *)); extern void as_list_delete_hook(void (*func)(const char *)); +extern int config_bgp_aspath_validate(const char *regstr); #endif /* _QUAGGA_BGP_FILTER_H */ diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 7036ededac..31df5165ae 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -9985,6 +9985,12 @@ static int bgp_show_regexp(struct vty *vty, struct bgp *bgp, const char *regstr, regex_t *regex; int rc; + if (!config_bgp_aspath_validate(regstr)) { + vty_out(vty, "Invalid character in as-path access-list %s\n", + regstr); + return CMD_WARNING_CONFIG_FAILED; + } + regex = bgp_regcomp(regstr); if (!regex) { vty_out(vty, "Can't compile regexp %s\n", regstr); -- 2.39.5