- dnsfilter: fix safesearch issue #268

This commit is contained in:
Aleksey Dmitrevskiy 2019-04-23 15:08:41 +03:00
parent 173ab2a3c1
commit 0794704f74
1 changed files with 5 additions and 3 deletions

View File

@ -649,15 +649,17 @@ func (d *Dnsfilter) checkSafeSearch(host string) (Result, error) {
return Result{}, err
}
res.IP = addrs[0]
// The next bug may occurs: LookupIP returns DNS64 mapped ipv4 address with zero-prefix
for _, i := range addrs {
if ipv4 := i.To4(); ipv4 != nil && len(i) == net.IPv6len {
if ipv4 := i.To4(); ipv4 != nil {
res.IP = ipv4
break
}
}
if len(res.IP) == 0 {
return Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", safeHost)
}
// Cache result
err = safeSearchCache.Set(host, res)
if err != nil {