Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow leading zeros in the IP address prefix. #140

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cedar-lean/Cedar/Spec/Ext/IPAddr.lean
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def IPNet.isMulticast (ip : IPNet) : Bool :=

def parseCIDR (str : String) (digits : Nat) (size : Nat) : Option (Fin (size + 1)) :=
let len := str.length
if 0 < len && len ≤ digits
if 0 < len && len ≤ digits && (str.startsWith "0" → str = "0")
then do
let n ← str.toNat?
if n ≤ size then .some (Fin.ofNat n) else .none
Expand Down
9 changes: 7 additions & 2 deletions cedar-lean/UnitTest/IPAddr.lean
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ def testsForInvalidStrings :=
testInvalid "F:A" "too few groups",
testInvalid "::ffff1" "group out of range",
testInvalid "F:AE::F:5:F:F:0/129" "prefix out of range",
testInvalid "::ffff:127.0.0.1" "no IPv4 embedded in IPv6"
testInvalid "::ffff:127.0.0.1" "no IPv4 embedded in IPv6",
testInvalid "::/00" "no leading zeros",
testInvalid "::/01" "no leading zeros",
testInvalid "::/001" "no leading zeros",
testInvalid "127.0.0.1/01" "no leading zeros",
testInvalid "F:AE::F:5:F:F:0/01" "no leading zeros"
]

deriving instance Inhabited for IPNet
Expand Down Expand Up @@ -163,4 +168,4 @@ def tests := [
-- Uncomment for interactive debugging
-- #eval TestSuite.runAll tests

end UnitTest.IPAddr
end UnitTest.IPAddr