domain: fix validIpv6 predicate release_20200227-2
authorClinton Ebadi <clinton@unknownlamer.org>
Fri, 28 Feb 2020 02:27:01 +0000 (21:27 -0500)
committerClinton Ebadi <clinton@unknownlamer.org>
Fri, 28 Feb 2020 02:27:01 +0000 (21:27 -0500)
Reject invalid IPs in format ":x" ("::" was already disallowed, so no
harm in requiring at least three segments), and allow localhost "::1"
as a valid format.

This completes the fix fwtool IPv6 LocalServer rule generation.

src/domain.sml

index a84a6d8..15bc8b7 100644 (file)
@@ -107,7 +107,7 @@ fun validIpv6 s =
                              | (_, n) => n) 0 fields
 
        fun noIpv4 maxLen =
-           length fields >= 2
+           length fields >= 3
            andalso length fields <= maxLen
            andalso empties <= 1
            andalso List.all (fn "" => true
@@ -123,8 +123,13 @@ fun validIpv6 s =
            in
                validIp maybeIpv4 andalso noIpv4 6
            end
+
+       fun localHost () =
+           length fields = 3
+           andalso empties = 2
+           andalso List.last fields = "1"
     in
-       noIpv4 8 orelse hasIpv4 ()
+       localHost () orelse noIpv4 8 orelse hasIpv4 ()
     end
 
 fun isIdent ch = Char.isLower ch orelse Char.isDigit ch