From 6b68920a3a3b9cf0e54cf988e756147de5d338da Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Thu, 10 Aug 2023 11:52:35 +0200 Subject: [PATCH] Go's LookupAddr will return non-absolute names, seemingly for single-label names from /etc/hosts, turn them into absolute names so our verifying forward lookups can succeed --- dns/resolver.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dns/resolver.go b/dns/resolver.go index 0a61311..4bcdb54 100644 --- a/dns/resolver.go +++ b/dns/resolver.go @@ -39,8 +39,8 @@ var ( // Resolver is the interface strict resolver implements. type Resolver interface { - LookupAddr(ctx context.Context, addr string) ([]string, error) - LookupCNAME(ctx context.Context, host string) (string, error) // NOTE: returns an error if no CNAME record is present. + LookupAddr(ctx context.Context, addr string) ([]string, error) // Always returns absolute names, with trailing dot. + LookupCNAME(ctx context.Context, host string) (string, error) // NOTE: returns an error if no CNAME record is present. LookupHost(ctx context.Context, host string) (addrs []string, err error) LookupIP(ctx context.Context, network, host string) ([]net.IP, error) LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error) @@ -131,6 +131,12 @@ func (r StrictResolver) LookupAddr(ctx context.Context, addr string) (resp []str defer resolveErrorHint(&err) resp, err = r.resolver().LookupAddr(ctx, addr) + // For addresses from /etc/hosts without dot, we add the missing trailing dot. + for i, s := range resp { + if !strings.HasSuffix(s, ".") { + resp[i] = s + "." + } + } return }