Skip to content

Commit a91ed83

Browse files
[release-branch.go1.16] net: don't reject null mx records
Bypass hostname validity checking when a null mx record is returned as, defined in RFC 7505. Updates #46979 Updates #46999 Change-Id: Ibe683bd6b47333a8ff30909fb2680ec8e10696ef Reviewed-on: https://go-review.googlesource.com/c/go/+/332094 Trust: Roland Shoemaker <[email protected]> Trust: Katie Hockman <[email protected]> Run-TryBot: Roland Shoemaker <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Katie Hockman <[email protected]> (cherry picked from commit 03761ed) Reviewed-on: https://go-review.googlesource.com/c/go/+/332371 Run-TryBot: Katie Hockman <[email protected]>
1 parent cb4cd9e commit a91ed83

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/net/dnsclient_unix_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,3 +1956,43 @@ func TestCVE202133195(t *testing.T) {
19561956
t.Errorf("LookupAddr returned unexpected error, got %q, want %q", err, expected)
19571957
}
19581958
}
1959+
1960+
func TestNullMX(t *testing.T) {
1961+
fake := fakeDNSServer{
1962+
rh: func(n, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) {
1963+
r := dnsmessage.Message{
1964+
Header: dnsmessage.Header{
1965+
ID: q.Header.ID,
1966+
Response: true,
1967+
RCode: dnsmessage.RCodeSuccess,
1968+
},
1969+
Questions: q.Questions,
1970+
Answers: []dnsmessage.Resource{
1971+
{
1972+
Header: dnsmessage.ResourceHeader{
1973+
Name: q.Questions[0].Name,
1974+
Type: dnsmessage.TypeMX,
1975+
Class: dnsmessage.ClassINET,
1976+
},
1977+
Body: &dnsmessage.MXResource{
1978+
MX: dnsmessage.MustNewName("."),
1979+
},
1980+
},
1981+
},
1982+
}
1983+
return r, nil
1984+
},
1985+
}
1986+
r := Resolver{PreferGo: true, Dial: fake.DialContext}
1987+
rrset, err := r.LookupMX(context.Background(), "golang.org")
1988+
if err != nil {
1989+
t.Fatalf("LookupMX: %v", err)
1990+
}
1991+
if want := []*MX{&MX{Host: "."}}; !reflect.DeepEqual(rrset, want) {
1992+
records := []string{}
1993+
for _, rr := range rrset {
1994+
records = append(records, fmt.Sprintf("%v", rr))
1995+
}
1996+
t.Errorf("records = [%v]; want [%v]", strings.Join(records, " "), want[0])
1997+
}
1998+
}

src/net/lookup.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,9 @@ func (r *Resolver) LookupMX(ctx context.Context, name string) ([]*MX, error) {
488488
if mx == nil {
489489
continue
490490
}
491-
if !isDomainName(mx.Host) {
491+
// Bypass the hostname validity check for targets which contain only a dot,
492+
// as this is used to represent a 'Null' MX record.
493+
if mx.Host != "." && !isDomainName(mx.Host) {
492494
return nil, &DNSError{Err: "MX target is invalid", Name: name}
493495
}
494496
}

0 commit comments

Comments
 (0)