Skip to content

Commit

Permalink
Go's LookupAddr will return non-absolute names, seemingly for single-…
Browse files Browse the repository at this point in the history
…label names from /etc/hosts, turn them into absolute names so our verifying forward lookups can succeed
  • Loading branch information
mjl- committed Aug 10, 2023
1 parent a30d8c1 commit 6b68920
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dns/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 6b68920

Please sign in to comment.