1
0
mirror of https://github.com/DNSCrypt/dnscrypt-proxy.git synced 2024-12-28 00:20:13 +01:00

fix: xtransport: Ensure we strip [] from host/ip before net.ParseIP

This commit is contained in:
Markus Linnala 2019-10-20 22:30:16 +03:00 committed by Frank Denis
parent ac4843b460
commit 890dcca270

View File

@ -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()