From d14d78e6486ec7ff0ed0358c35abbd143744cbed Mon Sep 17 00:00:00 2001 From: Markus Linnala Date: Sun, 20 Oct 2019 21:35:25 +0300 Subject: [PATCH] fix: xtransport: Check 'fallback_resolver' And also DefaultFallbackResolver. As far a I could see, value needs to have port defined too. dns.Exchange does seem to use address as such. --- dnscrypt-proxy/config.go | 18 +++++++++++++++++- dnscrypt-proxy/xtransport.go | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/dnscrypt-proxy/config.go b/dnscrypt-proxy/config.go index 329909e6..7f43249b 100644 --- a/dnscrypt-proxy/config.go +++ b/dnscrypt-proxy/config.go @@ -11,6 +11,7 @@ import ( "os" "path" "path/filepath" + "strconv" "strings" "time" @@ -272,11 +273,14 @@ func ConfigLoad(proxy *Proxy, svcFlag *string) error { proxy.xTransport = NewXTransport() proxy.xTransport.tlsDisableSessionTickets = config.TLSDisableSessionTickets proxy.xTransport.tlsCipherSuite = config.TLSCipherSuite - proxy.xTransport.fallbackResolver = config.FallbackResolver proxy.xTransport.mainProto = proxy.mainProto if len(config.FallbackResolver) > 0 { + if err := CheckResolver(config.FallbackResolver); err != nil { + dlog.Fatalf("fallback_resolver [%v]", err) + } proxy.xTransport.ignoreSystemDNS = config.IgnoreSystemDNS } + proxy.xTransport.fallbackResolver = config.FallbackResolver proxy.xTransport.useIPv4 = config.SourceIPv4 proxy.xTransport.useIPv6 = config.SourceIPv6 proxy.xTransport.keepAlive = time.Duration(config.KeepAlive) * time.Second @@ -690,3 +694,15 @@ func cdLocal() { } os.Chdir(filepath.Dir(exeFileName)) } + +func CheckResolver(resolver string) error { + host, port := ExtractHostAndPort(resolver, -1) + if ip := ParseIP(host); ip == nil { + return fmt.Errorf("Host does not parse as IP '%s'", resolver) + } else if port == -1 { + return fmt.Errorf("Port missing '%s'", resolver) + } else if _, err := strconv.ParseUint(strconv.Itoa(port), 10, 16); err != nil { + return fmt.Errorf("Port does not parse '%s' [%v]", resolver, err) + } + return nil +} diff --git a/dnscrypt-proxy/xtransport.go b/dnscrypt-proxy/xtransport.go index 569a89d0..3450ee20 100644 --- a/dnscrypt-proxy/xtransport.go +++ b/dnscrypt-proxy/xtransport.go @@ -53,6 +53,9 @@ type XTransport struct { } func NewXTransport() *XTransport { + if err := CheckResolver(DefaultFallbackResolver); err != nil { + panic("DefaultFallbackResolver does not parse") + } xTransport := XTransport{ cachedIPs: CachedIPs{cache: make(map[string]string)}, keepAlive: DefaultKeepAlive,