]> Cypherpunks repositories - gostls13.git/commitdiff
net: accept "." as a valid domain name
authorFilippo Valsorda <filippo@golang.org>
Mon, 1 Nov 2021 03:22:38 +0000 (23:22 -0400)
committerFilippo Valsorda <filippo@golang.org>
Fri, 5 Nov 2021 22:23:52 +0000 (22:23 +0000)
Fixes #45715

Change-Id: Ibdaa91c97d34473061b377325ebe9a3bf5696c8e
Reviewed-on: https://go-review.googlesource.com/c/go/+/360314
Trust: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/net/dnsclient.go
src/net/dnsclient_unix_test.go
src/net/lookup.go

index 3c1a12995a8033e044f74a19c1bb29da30f375a2..a779c37e53df578e0651aff6c438048380046562 100644 (file)
@@ -76,6 +76,11 @@ func equalASCIIName(x, y dnsmessage.Name) bool {
 // (currently restricted to hostname-compatible "preferred name" LDH labels and
 // SRV-like "underscore labels"; see golang.org/issue/12421).
 func isDomainName(s string) bool {
+       // The root domain name is valid. See golang.org/issue/45715.
+       if s == "." {
+               return true
+       }
+
        // See RFC 1035, RFC 3696.
        // Presentation format has dots before every label except the first, and the
        // terminal empty label is optional here because we assume fully-qualified
index 1d704d021e2bf0db62ce5a4890b3c2c7a372500c..14366eca8c63b100eb05c6a5cfefa12cc5f66c76 100644 (file)
@@ -2120,3 +2120,44 @@ func TestNullMX(t *testing.T) {
                t.Errorf("records = [%v]; want [%v]", strings.Join(records, " "), want[0])
        }
 }
+
+func TestRootNS(t *testing.T) {
+       // See https://golang.org/issue/45715.
+       fake := fakeDNSServer{
+               rh: func(n, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) {
+                       r := dnsmessage.Message{
+                               Header: dnsmessage.Header{
+                                       ID:       q.Header.ID,
+                                       Response: true,
+                                       RCode:    dnsmessage.RCodeSuccess,
+                               },
+                               Questions: q.Questions,
+                               Answers: []dnsmessage.Resource{
+                                       {
+                                               Header: dnsmessage.ResourceHeader{
+                                                       Name:  q.Questions[0].Name,
+                                                       Type:  dnsmessage.TypeNS,
+                                                       Class: dnsmessage.ClassINET,
+                                               },
+                                               Body: &dnsmessage.NSResource{
+                                                       NS: dnsmessage.MustNewName("i.root-servers.net."),
+                                               },
+                                       },
+                               },
+                       }
+                       return r, nil
+               },
+       }
+       r := Resolver{PreferGo: true, Dial: fake.DialContext}
+       rrset, err := r.LookupNS(context.Background(), ".")
+       if err != nil {
+               t.Fatalf("LookupNS: %v", err)
+       }
+       if want := []*NS{&NS{Host: "i.root-servers.net."}}; !reflect.DeepEqual(rrset, want) {
+               records := []string{}
+               for _, rr := range rrset {
+                       records = append(records, fmt.Sprintf("%v", rr))
+               }
+               t.Errorf("records = [%v]; want [%v]", strings.Join(records, " "), want[0])
+       }
+}
index e10c71ae753a91a6262d34a69f7310144c0e3a9e..ff4ddbeb82baabed7bb9374ae47de0489688b502 100644 (file)
@@ -558,9 +558,7 @@ func (r *Resolver) LookupMX(ctx context.Context, name string) ([]*MX, error) {
                if mx == nil {
                        continue
                }
-               // Bypass the hostname validity check for targets which contain only a dot,
-               // as this is used to represent a 'Null' MX record.
-               if mx.Host != "." && !isDomainName(mx.Host) {
+               if !isDomainName(mx.Host) {
                        continue
                }
                filteredMX = append(filteredMX, mx)