From 0794704f740db3c6ab73ee4d6287dc6f40ec4911 Mon Sep 17 00:00:00 2001 From: Aleksey Dmitrevskiy Date: Tue, 23 Apr 2019 15:08:41 +0300 Subject: [PATCH] - dnsfilter: fix safesearch issue #268 --- dnsfilter/dnsfilter.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dnsfilter/dnsfilter.go b/dnsfilter/dnsfilter.go index c487d7d2..20ca4222 100644 --- a/dnsfilter/dnsfilter.go +++ b/dnsfilter/dnsfilter.go @@ -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 {