]> Cypherpunks repositories - gostls13.git/commitdiff
net: don't reject null mx records
authorRoland Shoemaker <roland@golang.org>
Wed, 30 Jun 2021 21:28:18 +0000 (14:28 -0700)
committerRoland Shoemaker <roland@golang.org>
Thu, 1 Jul 2021 19:09:57 +0000 (19:09 +0000)
Bypass hostname validity checking when a null mx record is returned as,
defined in RFC 7505.

Updates #46979

Change-Id: Ibe683bd6b47333a8ff30909fb2680ec8e10696ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/332094
Trust: Roland Shoemaker <roland@golang.org>
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
src/net/dnsclient_unix_test.go
src/net/lookup.go

index d69107a2f23ba614e19fc4c521ec3652ba178e85..59cdd2bf3e2867c08b0297448940f39eef26ca46 100644 (file)
@@ -1957,3 +1957,43 @@ func TestCVE202133195(t *testing.T) {
                t.Errorf("LookupAddr returned unexpected error, got %q, want %q", err, expected)
        }
 }
+
+func TestNullMX(t *testing.T) {
+       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.TypeMX,
+                                                       Class: dnsmessage.ClassINET,
+                                               },
+                                               Body: &dnsmessage.MXResource{
+                                                       MX: dnsmessage.MustNewName("."),
+                                               },
+                                       },
+                               },
+                       }
+                       return r, nil
+               },
+       }
+       r := Resolver{PreferGo: true, Dial: fake.DialContext}
+       rrset, err := r.LookupMX(context.Background(), "golang.org")
+       if err != nil {
+               t.Fatalf("LookupMX: %v", err)
+       }
+       if want := []*MX{&MX{Host: "."}}; !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 02a4cdcd1ee2f651703d6e1b48e6826c06f3457a..b5af3a0f86735c0c25c6baef69ca9f989a9396db 100644 (file)
@@ -500,7 +500,9 @@ func (r *Resolver) LookupMX(ctx context.Context, name string) ([]*MX, error) {
                if mx == nil {
                        continue
                }
-               if !isDomainName(mx.Host) {
+               // 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) {
                        return nil, &DNSError{Err: "MX target is invalid", Name: name}
                }
        }