Skip to content

Commit

Permalink
Disallow leading zeros in the prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
shaobo-he-aws committed Oct 27, 2023
1 parent 5ef3bf2 commit cf7243d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions cedar-dafny/def/ext/ipaddr.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ module def.ext.ipaddr.parseIPAddr {
if 0 < |ds| <= 2
then
var n := DecStrToNat(ds);
if n <= V4_SIZE then
Some((n, ns'))
if n <= V4_SIZE && (ds[0] == '0' ==> (|ds| == 1 && n == 0)) then
Some((n, ns'))
else None
else None
case None => None
Expand Down Expand Up @@ -530,7 +530,8 @@ module def.ext.ipaddr.parseIPAddr {
case Some((ds, ns')) =>
if 0 < |ds| <= 3 then
var n := DecStrToNat(ds);
if n <= V6_SIZE then Some((n, ns'))
if n <= V6_SIZE && (ds[0] == '0' ==> (|ds| == 1 && n == 0)) then
Some((n, ns'))
else None
else None
case None => None
Expand Down
5 changes: 4 additions & 1 deletion cedar-dafny/test/ipaddr.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ module test.ipaddr {
"::::", // too many double colons
"F:AE::F:5:F:F:0:0", // too many groups
"F:A:F:5:F:F:0:0:1", // too many groups
"F:A" // too few groups
"F:A", // too few groups
"::/01", // leading zeros
"::/001", // leading zeros
"127.0.0.1/01" // leading zeros
];
var i := |invalidStr| - 1;
while 0 <= i {
Expand Down

0 comments on commit cf7243d

Please sign in to comment.