]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/command_match.c
Merge pull request #5746 from donaldsharp/bgp_sa
[mirror_frr.git] / lib / command_match.c
index 8b34d1e3eb907e6848e75ea6af5edbe23d16c61a..0195aebc17f7fd0a76e3ff7e5e3ba5c959389497 100644 (file)
@@ -714,7 +714,7 @@ static enum match_type match_ipv4(const char *str)
                                dots++;
                                break;
                        }
-                       if (!isdigit((int)*str))
+                       if (!isdigit((unsigned char)*str))
                                return no_match;
 
                        str++;
@@ -723,8 +723,13 @@ static enum match_type match_ipv4(const char *str)
                if (str - sp > 3)
                        return no_match;
 
-               strncpy(buf, sp, str - sp);
-               if (atoi(buf) > 255)
+               memcpy(buf, sp, str - sp);
+
+               int v = atoi(buf);
+
+               if (v > 255)
+                       return no_match;
+               if (v > 0 && buf[0] == '0')
                        return no_match;
 
                nums++;
@@ -765,7 +770,7 @@ static enum match_type match_ipv4_prefix(const char *str)
                                break;
                        }
 
-                       if (!isdigit((int)*str))
+                       if (!isdigit((unsigned char)*str))
                                return no_match;
 
                        str++;
@@ -774,8 +779,13 @@ static enum match_type match_ipv4_prefix(const char *str)
                if (str - sp > 3)
                        return no_match;
 
-               strncpy(buf, sp, str - sp);
-               if (atoi(buf) > 255)
+               memcpy(buf, sp, str - sp);
+
+               int v = atoi(buf);
+
+               if (v > 255)
+                       return no_match;
+               if (v > 0 && buf[0] == '0')
                        return no_match;
 
                if (dots == 3) {
@@ -797,7 +807,7 @@ static enum match_type match_ipv4_prefix(const char *str)
 
        sp = str;
        while (*str != '\0') {
-               if (!isdigit((int)*str))
+               if (!isdigit((unsigned char)*str))
                        return no_match;
 
                str++;