woolf ian has uploaded this change for review.
net: fix the return of Resolver.LookupIP when the host is empty
Fixes #53995
Change-Id: Ib0de237b57382feb6b8070f2310945aef6c7db01
---
M src/net/lookup.go
1 file changed, 16 insertions(+), 0 deletions(-)
diff --git a/src/net/lookup.go b/src/net/lookup.go
index 7f3d201..a9a541e 100644
--- a/src/net/lookup.go
+++ b/src/net/lookup.go
@@ -224,10 +224,15 @@
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)
To view, visit change 419734. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: woolf ian.
Set Ready For Review
Attention is currently required from: Ian Lance Taylor.
1 comment:
Patchset:
Thanks. A change like this should have a test.
done
To view, visit change 419734. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil, Ian Lance Taylor, woolf ian.
1 comment:
Patchset:
done
I am not familiar with this code, but it seems to me that the bug is in internetAddrList in ipsock.go and that that is the function that should be fixed.
To view, visit change 419734. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: David Brink, Ian Lance Taylor, woolf ian.
Patch set 4:Run-TryBot +1
1 comment:
Patchset:
I am not familiar with this code, but it seems to me that the bug is in internetAddrList in ipsock. […]
I'm not especially familiar with this either, but from a quick look through things internetAddrList is used in cases where we do want to treat "" as a zero-valued address. For example, `Dial("tcp",":80")` dials port 80 on the local machine, and changing internetAddrList's behavior breaks that.
There's probably a larger refactoring that could be done to make things less surprising internally, but changing just `Resolver.LookupIP` for now seems reasonable to me.
To view, visit change 419734. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: David Brink, Ian Lance Taylor, woolf ian.
Patch set 4:Code-Review +2
Attention is currently required from: David Brink, Ian Lance Taylor, woolf ian.
Patch set 4:Code-Review +1
Damien Neil submitted this change.
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 <dn...@google.com>
Reviewed-by: David Chase <drc...@google.com>
TryBot-Result: Gopher Robot <go...@golang.org>
Run-TryBot: Damien Neil <dn...@google.com>
---
M src/net/lookup.go
M src/net/lookup_test.go
2 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/src/net/lookup.go b/src/net/lookup.go
index b283c67..969c902 100644
--- a/src/net/lookup.go
+++ b/src/net/lookup.go
@@ -224,10 +224,15 @@
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)
diff --git a/src/net/lookup_test.go b/src/net/lookup_test.go
index 3a31f56..24d4fbf 100644
--- a/src/net/lookup_test.go
+++ b/src/net/lookup_test.go
@@ -1208,6 +1208,17 @@
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())
To view, visit change 419734. To unsubscribe, or for help writing mail filters, visit settings.