Skip to content

Commit

Permalink
lib: reject leading 0 in ipv4 decimal quad
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
qlyoung committed Oct 7, 2019
1 parent 7310aae commit e843208
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/command_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e843208

Please sign in to comment.