diff options
author | 2019-08-21 15:34:21 +0200 | |
---|---|---|
committer | 2019-08-21 06:34:21 -0700 | |
commit | f888c5f7f62e8f789fe4939faaa9e3b3a3f7c554 (patch) | |
tree | 26a179cdb649c7c109f89b3b0caed801a46201ef | |
parent | 27f44f60eed0797d19be6d99ccaae067bc41c337 (diff) | |
download | coredns-f888c5f7f62e8f789fe4939faaa9e3b3a3f7c554.tar.gz coredns-f888c5f7f62e8f789fe4939faaa9e3b3a3f7c554.tar.zst coredns-f888c5f7f62e8f789fe4939faaa9e3b3a3f7c554.zip |
Validate zone during normalization (#3165)
-rw-r--r-- | core/dnsserver/address.go | 9 | ||||
-rw-r--r-- | core/dnsserver/address_test.go | 1 |
2 files changed, 9 insertions, 1 deletions
diff --git a/core/dnsserver/address.go b/core/dnsserver/address.go index 1a69c33b8..9146ef650 100644 --- a/core/dnsserver/address.go +++ b/core/dnsserver/address.go @@ -3,6 +3,7 @@ package dnsserver import ( "fmt" "net" + "net/url" "strings" "github.com/coredns/coredns/plugin" @@ -52,7 +53,13 @@ func normalizeZone(str string) (zoneAddr, error) { } } - return zoneAddr{Zone: dns.Fqdn(host), Port: port, Transport: trans, IPNet: ipnet}, nil + z := zoneAddr{Zone: dns.Fqdn(host), Port: port, Transport: trans, IPNet: ipnet} + _, err = url.ParseRequestURI(z.String()) + if err != nil { + return zoneAddr{}, err + } + + return z, nil } // SplitProtocolHostPort splits a full formed address like "dns://[::1]:53" into parts. diff --git a/core/dnsserver/address_test.go b/core/dnsserver/address_test.go index 6d4d0beab..86360d8f0 100644 --- a/core/dnsserver/address_test.go +++ b/core/dnsserver/address_test.go @@ -28,6 +28,7 @@ func TestNormalizeZone(t *testing.T) { {"https://.:8443", "https://.:8443", false}, {"https://..", "://:", true}, {"https://.:", "://:", true}, + {"dns://.:1053{.:53", "://:", true}, } { addr, err := normalizeZone(test.input) actual := addr.String() |