From 890dcca270cdd066279c4a415ab86d97b421f14a Mon Sep 17 00:00:00 2001 From: Markus Linnala Date: Sun, 20 Oct 2019 22:30:16 +0300 Subject: [PATCH] fix: xtransport: Ensure we strip [] from host/ip before net.ParseIP --- dnscrypt-proxy/xtransport.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dnscrypt-proxy/xtransport.go b/dnscrypt-proxy/xtransport.go index d3b9efd7..569a89d0 100644 --- a/dnscrypt-proxy/xtransport.go +++ b/dnscrypt-proxy/xtransport.go @@ -68,6 +68,10 @@ func NewXTransport() *XTransport { return &xTransport } +func ParseIP(ipStr string) net.IP { + return net.ParseIP(strings.TrimRight(strings.TrimLeft(ipStr, "["), "]")) +} + func (xTransport *XTransport) clearCache() { xTransport.cachedIPs.Lock() xTransport.cachedIPs.cache = make(map[string]string) @@ -232,7 +236,7 @@ func (xTransport *XTransport) Fetch(method string, url *url.URL, accept string, resolveByProxy = true } var foundIP *string - if !resolveByProxy && net.ParseIP(host) == nil { + if !resolveByProxy && ParseIP(host) == nil { xTransport.cachedIPs.RLock() cachedIP := xTransport.cachedIPs.cache[host] xTransport.cachedIPs.RUnlock()