[go] net: fix the return of Resolver.LookupIP when the host is empty

33 views
Skip to first unread message

woolf ian (Gerrit)

unread,
Jul 27, 2022, 12:57:19 PM7/27/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

woolf ian has uploaded this change for review.

View Change

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.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib0de237b57382feb6b8070f2310945aef6c7db01
Gerrit-Change-Number: 419734
Gerrit-PatchSet: 1
Gerrit-Owner: woolf ian <btw51...@gmail.com>
Gerrit-MessageType: newchange

woolf ian (Gerrit)

unread,
Jul 27, 2022, 11:34:47 PM7/27/22
to goph...@pubsubhelper.golang.org, Ian Lance Taylor, golang-co...@googlegroups.com

Attention is currently required from: woolf ian.

Set Ready For Review

View Change

    To view, visit change 419734. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib0de237b57382feb6b8070f2310945aef6c7db01
    Gerrit-Change-Number: 419734
    Gerrit-PatchSet: 4
    Gerrit-Owner: woolf ian <btw51...@gmail.com>
    Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Attention: woolf ian <btw51...@gmail.com>
    Gerrit-Comment-Date: Thu, 28 Jul 2022 03:34:41 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    woolf ian (Gerrit)

    unread,
    Jul 27, 2022, 11:36:47 PM7/27/22
    to goph...@pubsubhelper.golang.org, Ian Lance Taylor, golang-co...@googlegroups.com

    Attention is currently required from: Ian Lance Taylor.

    View Change

    1 comment:

    • Patchset:

    To view, visit change 419734. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib0de237b57382feb6b8070f2310945aef6c7db01
    Gerrit-Change-Number: 419734
    Gerrit-PatchSet: 4
    Gerrit-Owner: woolf ian <btw51...@gmail.com>
    Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Comment-Date: Thu, 28 Jul 2022 03:36:42 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Ian Lance Taylor <ia...@golang.org>
    Gerrit-MessageType: comment

    David Brink (Gerrit)

    unread,
    Aug 10, 2022, 9:48:47 PM8/10/22
    to woolf ian, goph...@pubsubhelper.golang.org, Damien Neil, Ian Lance Taylor, golang-co...@googlegroups.com

    Attention is currently required from: Damien Neil, Ian Lance Taylor, woolf ian.

    View Change

    1 comment:

    • Patchset:

      • Patch Set #3:

        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.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib0de237b57382feb6b8070f2310945aef6c7db01
    Gerrit-Change-Number: 419734
    Gerrit-PatchSet: 4
    Gerrit-Owner: woolf ian <btw51...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-CC: David Brink <dbr...@akamai.com>
    Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Attention: Damien Neil <dn...@google.com>
    Gerrit-Attention: woolf ian <btw51...@gmail.com>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Comment-Date: Tue, 09 Aug 2022 10:40:16 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: woolf ian <btw51...@gmail.com>

    Damien Neil (Gerrit)

    unread,
    Aug 24, 2022, 8:37:44 PM8/24/22
    to woolf ian, goph...@pubsubhelper.golang.org, David Brink, Ian Lance Taylor, golang-co...@googlegroups.com

    Attention is currently required from: David Brink, Ian Lance Taylor, woolf ian.

    Patch set 4:Run-TryBot +1

    View Change

    1 comment:

    • Patchset:

      • Patch Set #3:

        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.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib0de237b57382feb6b8070f2310945aef6c7db01
    Gerrit-Change-Number: 419734
    Gerrit-PatchSet: 4
    Gerrit-Owner: woolf ian <btw51...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-CC: David Brink <dbr...@akamai.com>
    Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Attention: David Brink <dbr...@akamai.com>
    Gerrit-Attention: woolf ian <btw51...@gmail.com>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Comment-Date: Thu, 25 Aug 2022 00:37:39 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Comment-In-Reply-To: David Brink <dbr...@akamai.com>

    Damien Neil (Gerrit)

    unread,
    Aug 24, 2022, 9:09:02 PM8/24/22
    to woolf ian, goph...@pubsubhelper.golang.org, Gopher Robot, David Brink, Ian Lance Taylor, golang-co...@googlegroups.com

    Attention is currently required from: David Brink, Ian Lance Taylor, woolf ian.

    Patch set 4:Code-Review +2

    View Change

      To view, visit change 419734. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ib0de237b57382feb6b8070f2310945aef6c7db01
      Gerrit-Change-Number: 419734
      Gerrit-PatchSet: 4
      Gerrit-Owner: woolf ian <btw51...@gmail.com>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-CC: David Brink <dbr...@akamai.com>
      Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Attention: David Brink <dbr...@akamai.com>
      Gerrit-Attention: woolf ian <btw51...@gmail.com>
      Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Comment-Date: Thu, 25 Aug 2022 01:08:56 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      Gerrit-MessageType: comment

      David Chase (Gerrit)

      unread,
      Aug 26, 2022, 1:40:09 PM8/26/22
      to woolf ian, goph...@pubsubhelper.golang.org, Damien Neil, Gopher Robot, David Brink, Ian Lance Taylor, golang-co...@googlegroups.com

      Attention is currently required from: David Brink, Ian Lance Taylor, woolf ian.

      Patch set 4:Code-Review +1

      View Change

        To view, visit change 419734. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ib0de237b57382feb6b8070f2310945aef6c7db01
        Gerrit-Change-Number: 419734
        Gerrit-PatchSet: 4
        Gerrit-Owner: woolf ian <btw51...@gmail.com>
        Gerrit-Reviewer: Damien Neil <dn...@google.com>
        Gerrit-Reviewer: David Chase <drc...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-CC: David Brink <dbr...@akamai.com>
        Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Attention: David Brink <dbr...@akamai.com>
        Gerrit-Attention: woolf ian <btw51...@gmail.com>
        Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Comment-Date: Fri, 26 Aug 2022 17:40:05 +0000

        Damien Neil (Gerrit)

        unread,
        Aug 26, 2022, 6:52:55 PM8/26/22
        to woolf ian, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, David Chase, Gopher Robot, David Brink, Ian Lance Taylor, golang-co...@googlegroups.com

        Damien Neil submitted this change.

        View Change


        Approvals: Damien Neil: Looks good to me, approved; Run TryBots Gopher Robot: TryBots succeeded David Chase: Looks good to me, but someone else must approve
        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.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ib0de237b57382feb6b8070f2310945aef6c7db01
        Gerrit-Change-Number: 419734
        Gerrit-PatchSet: 5
        Gerrit-Owner: woolf ian <btw51...@gmail.com>
        Gerrit-Reviewer: Damien Neil <dn...@google.com>
        Gerrit-Reviewer: David Chase <drc...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-CC: David Brink <dbr...@akamai.com>
        Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
        Gerrit-MessageType: merged
        Reply all
        Reply to author
        Forward
        0 new messages