summaryrefslogtreecommitdiff
path: root/lib/command_match.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2019-10-07 15:36:39 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2019-10-07 15:36:39 +0000
commite843208299db9a2ebf3b22e21e1a6d33cfdc35af (patch)
tree4486c4b1172cff47f97f9358f25c0f27dfe102c2 /lib/command_match.c
parent7310aae9ae0a7a88042ae19e9f480169af8486f7 (diff)
lib: reject leading 0 in ipv4 decimal quad
inet_pton() is used to parse ipv4 addresses internally, therefore FRR does not support octal notation for quads. The ipv4 cli token validator should make sure that str2prefix() can parse tokens it allows, and str2prefix uses inet_pton, so we have to disallow leading zeros in ipv4 quads. In short, 1.1.1.01 is no longer valid and must be expressed as 1.1.1.1. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command_match.c')
-rw-r--r--lib/command_match.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/command_match.c b/lib/command_match.c
index 26d763849d..0195aebc17 100644
--- a/lib/command_match.c
+++ b/lib/command_match.c
@@ -724,7 +724,12 @@ static enum match_type match_ipv4(const char *str)
return no_match;
memcpy(buf, sp, str - sp);
- if (atoi(buf) > 255)
+
+ int v = atoi(buf);
+
+ if (v > 255)
+ return no_match;
+ if (v > 0 && buf[0] == '0')
return no_match;
nums++;
@@ -775,7 +780,12 @@ static enum match_type match_ipv4_prefix(const char *str)
return no_match;
memcpy(buf, sp, str - sp);
- if (atoi(buf) > 255)
+
+ int v = atoi(buf);
+
+ if (v > 255)
+ return no_match;
+ if (v > 0 && buf[0] == '0')
return no_match;
if (dots == 3) {