Skip to content

Commit

Permalink
Merge pull request #5112 from qlyoung/cli-reject-ipv4-leading-zero
Browse files Browse the repository at this point in the history
lib: reject leading 0 in ipv4 decimal quad
  • Loading branch information
Jafaral authored Oct 7, 2019
2 parents f7192aa + e843208 commit 4668ac9
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 4668ac9

Please sign in to comment.