mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
net: Resolver.LookupIP return error for empty string
Fixes #53995 Change-Id: Ib0de237b57382feb6b8070f2310945aef6c7db01 Reviewed-on: https://go-review.googlesource.com/c/go/+/419734 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
This commit is contained in:
parent
acabf87127
commit
333681d6a8
|
@ -224,10 +224,15 @@ func (r *Resolver) LookupIP(ctx context.Context, network, host string) ([]IP, er
|
|||
default:
|
||||
return nil, UnknownNetworkError(network)
|
||||
}
|
||||
|
||||
if host == "" {
|
||||
return nil, &DNSError{Err: errNoSuchHost.Error(), Name: host, IsNotFound: true}
|
||||
}
|
||||
addrs, err := r.internetAddrList(ctx, afnet, host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ips := make([]IP, 0, len(addrs))
|
||||
for _, addr := range addrs {
|
||||
ips = append(ips, addr.(*IPAddr).IP)
|
||||
|
|
|
@ -1208,6 +1208,17 @@ func TestLookupIPAddrConcurrentCallsForNetworks(t *testing.T) {
|
|||
wg.Wait()
|
||||
}
|
||||
|
||||
// Issue 53995: Resolver.LookupIP should return error for empty host name.
|
||||
func TestResolverLookupIPWithEmptyHost(t *testing.T) {
|
||||
_, err := DefaultResolver.LookupIP(context.Background(), "ip", "")
|
||||
if err == nil {
|
||||
t.Fatal("DefaultResolver.LookupIP for empty host success, want no host error")
|
||||
}
|
||||
if !strings.HasSuffix(err.Error(), errNoSuchHost.Error()) {
|
||||
t.Fatalf("lookup error = %v, want %v", err, errNoSuchHost)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithUnexpiredValuesPreserved(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
|
|
Loading…
Reference in a new issue