]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Validate as-path access-list before continuing regarding invalid chars
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Wed, 29 Aug 2018 16:12:30 +0000 (19:12 +0300)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Tue, 25 Jun 2019 05:55:12 +0000 (08:55 +0300)
Signed-off-by: Donatas Abraitis donatas.abraitis@gmail.com
bgpd/bgp_filter.c

index ae9d805b055a846fdefc65c0a3170e6318fbf6bc..c7977a9af4c800840ea3245e163194cb72720abc 100644 (file)
@@ -391,16 +391,25 @@ static int as_list_dup_check(struct as_list *aslist, struct as_filter *new)
        return 0;
 }
 
-DEFUN (ip_as_path,
-       ip_as_path_cmd,
-       "ip as-path access-list WORD <deny|permit> LINE...",
-       IP_STR
-       "BGP autonomous system path filter\n"
-       "Specify an access list name\n"
-       "Regular expression access list name\n"
-       "Specify packets to reject\n"
-       "Specify packets to forward\n"
-       "A regular-expression to match the BGP AS paths\n")
+static int config_bgp_aspath_validate(const char *regstr)
+{
+       char valid_chars[] = "1234567890_^|[,{}() ]$*+.?-";
+
+       if (strspn(regstr, valid_chars) == strlen(regstr))
+               return 1;
+
+       return 0;
+}
+
+DEFUN(ip_as_path, ip_as_path_cmd,
+      "ip as-path access-list WORD <deny|permit> LINE...",
+      IP_STR
+      "BGP autonomous system path filter\n"
+      "Specify an access list name\n"
+      "Regular expression access list name\n"
+      "Specify packets to reject\n"
+      "Specify packets to forward\n"
+      "A regular-expression (1234567890_(^|[,{}() ]|$)) to match the BGP AS paths\n")
 {
        int idx = 0;
        enum as_filter_type type;
@@ -428,6 +437,12 @@ DEFUN (ip_as_path,
                return CMD_WARNING_CONFIG_FAILED;
        }
 
+       if (!config_bgp_aspath_validate(regstr)) {
+               vty_out(vty, "Invalid character in as-path access-list %s\n",
+                       regstr);
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
        asfilter = as_filter_make(regex, regstr, type);
 
        XFREE(MTYPE_TMP, regstr);
@@ -444,17 +459,15 @@ DEFUN (ip_as_path,
        return CMD_SUCCESS;
 }
 
-DEFUN (no_ip_as_path,
-       no_ip_as_path_cmd,
-       "no ip as-path access-list WORD <deny|permit> LINE...",
-       NO_STR
-       IP_STR
-       "BGP autonomous system path filter\n"
-       "Specify an access list name\n"
-       "Regular expression access list name\n"
-       "Specify packets to reject\n"
-       "Specify packets to forward\n"
-       "A regular-expression to match the BGP AS paths\n")
+DEFUN(no_ip_as_path, no_ip_as_path_cmd,
+      "no ip as-path access-list WORD <deny|permit> LINE...",
+      NO_STR IP_STR
+      "BGP autonomous system path filter\n"
+      "Specify an access list name\n"
+      "Regular expression access list name\n"
+      "Specify packets to reject\n"
+      "Specify packets to forward\n"
+      "A regular-expression (1234567890_(^|[,{}() ]|$)) to match the BGP AS paths\n")
 {
        int idx = 0;
        enum as_filter_type type;
@@ -488,6 +501,12 @@ DEFUN (no_ip_as_path,
        argv_find(argv, argc, "LINE", &idx);
        regstr = argv_concat(argv, argc, idx);
 
+       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);