mirror of
https://github.com/golang/go.git
synced 2025-11-01 09:10:57 +00:00
net: avoid an infinite loop in LookupAddr
If a request for a PTR record returned a response with a non-PTR answer, goLookupPTR would loop forever. Skipping non-PTR answers guarantees progress through the DNS response. Fixes #34660 Change-Id: I56f9d21e5342d07e7d843d253267e93a29707904 Reviewed-on: https://go-review.googlesource.com/c/go/+/198460 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
e85ffec784
commit
f0e940ebc9
2 changed files with 55 additions and 0 deletions
|
|
@ -1753,3 +1753,50 @@ func TestDNSUseTCP(t *testing.T) {
|
|||
t.Fatal("exchange failed:", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Issue 34660: PTR response with non-PTR answers should ignore non-PTR
|
||||
func TestPTRandNonPTR(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.TypePTR,
|
||||
Class: dnsmessage.ClassINET,
|
||||
},
|
||||
Body: &dnsmessage.PTRResource{
|
||||
PTR: dnsmessage.MustNewName("golang.org."),
|
||||
},
|
||||
},
|
||||
{
|
||||
Header: dnsmessage.ResourceHeader{
|
||||
Name: q.Questions[0].Name,
|
||||
Type: dnsmessage.TypeTXT,
|
||||
Class: dnsmessage.ClassINET,
|
||||
},
|
||||
Body: &dnsmessage.TXTResource{
|
||||
TXT: []string{"PTR 8 6 60 ..."}, // fake RRSIG
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return r, nil
|
||||
},
|
||||
}
|
||||
r := Resolver{PreferGo: true, Dial: fake.DialContext}
|
||||
names, err := r.lookupAddr(context.Background(), "192.0.2.123")
|
||||
if err != nil {
|
||||
t.Fatalf("LookupAddr: %v", err)
|
||||
}
|
||||
if want := []string{"golang.org."}; !reflect.DeepEqual(names, want) {
|
||||
t.Errorf("names = %q; want %q", names, want)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue