]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: some ASNUMs should be forbidden
authoranlan_cs <vic.lan@pica8.com>
Wed, 22 Feb 2023 12:57:07 +0000 (20:57 +0800)
committeranlan_cs <vic.lan@pica8.com>
Fri, 24 Feb 2023 13:13:19 +0000 (21:13 +0800)
In current code, some ASNUMs with redundant zero are legal,
e.g. "1.01", "01.1", "1.001", "001.1", and more.  They should
be forbidden.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
lib/asn.c

index c64666375d0915d18d2230f1620de6390439fb97..4042f5846cc1f4719a27cdca279e174051e1d8e9 100644 (file)
--- a/lib/asn.c
+++ b/lib/asn.c
@@ -52,6 +52,10 @@ static bool asn_str2asn_internal(const char *asstring, as_t *asn,
        if  (!isdigit((unsigned char)*p))
                goto end;
 
+       /* leading zero is forbidden */
+       if (*p == '0' && isdigit((unsigned char)*(p + 1)))
+               goto end;
+
        temp_val = 0;
        while (isdigit((unsigned char)*p)) {
                digit = (*p) - '0';
@@ -65,11 +69,17 @@ static bool asn_str2asn_internal(const char *asstring, as_t *asn,
        high = (uint32_t)temp_val;
        if (*p == '.') { /* dot format */
                p++;
-               temp_val = 0;
+
                if (*p == '\0' && partial) {
                        *partial = true;
                        goto end;
                }
+
+               /* leading zero is forbidden */
+               if (*p == '0' && isdigit((unsigned char)*(p + 1)))
+                       goto end;
+
+               temp_val = 0;
                while (isdigit((unsigned char)*p)) {
                        digit = (*p) - '0';
                        temp_val *= 10;