From 3f097341ec5756f7f1cbc2f4f1a66eaa337e72ec Mon Sep 17 00:00:00 2001 From: Clinton Ebadi Date: Thu, 27 Feb 2020 21:27:01 -0500 Subject: [PATCH] domain: fix validIpv6 predicate 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/domain.sml b/src/domain.sml index a84a6d8..15bc8b7 100644 --- a/src/domain.sml +++ b/src/domain.sml @@ -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 -- 2.20.1