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

This commit is contained in:
Mechiel Lukkien 2023-08-10 11:52:35 +02:00
parent a30d8c1378
commit 6b68920a3a
No known key found for this signature in database

View file

@ -39,7 +39,7 @@ var (
// Resolver is the interface strict resolver implements. // Resolver is the interface strict resolver implements.
type Resolver interface { type Resolver interface {
LookupAddr(ctx context.Context, addr string) ([]string, error) 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. 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) LookupHost(ctx context.Context, host string) (addrs []string, err error)
LookupIP(ctx context.Context, network, host string) ([]net.IP, error) LookupIP(ctx context.Context, network, host string) ([]net.IP, error)
@ -131,6 +131,12 @@ func (r StrictResolver) LookupAddr(ctx context.Context, addr string) (resp []str
defer resolveErrorHint(&err) defer resolveErrorHint(&err)
resp, err = r.resolver().LookupAddr(ctx, addr) 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 return
} }