Skip to content

Commit

Permalink
fix: dns id checking
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Aug 3, 2023
1 parent 4747f4a commit 3e513ae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ All long form (--) flags can be toggled with the dig-standard +[no]flag notation
return err
}
if !opts.NoIDCheck && reply.Id != msg.Id {
return dns.ErrId
return fmt.Errorf("ID mismatch: expected %d, got %d", msg.Id, reply.Id)
}
replies = append(replies, reply)
}
Expand Down
3 changes: 3 additions & 0 deletions transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
func validQuery() *dns.Msg {
msg := dns.Msg{}
msg.RecursionDesired = true
msg.Id = dns.Id()
msg.Question = []dns.Question{{
Name: "example.com.",
Qtype: dns.StringToType["A"],
Expand All @@ -23,6 +24,7 @@ func validQuery() *dns.Msg {
func invalidQuery() *dns.Msg {
msg := &dns.Msg{}
msg.RecursionDesired = true
msg.Id = dns.Id()
msg.Question = []dns.Question{{
Name: "invalid label!",
}}
Expand All @@ -49,6 +51,7 @@ func transportHarness(t *testing.T, transport Transport) {
assert.NotNil(t, err)
} else {
assert.Nil(t, err)
assert.Equal(t, tc.Query.Id, reply.Id)
for _, q := range tc.Query.Question {
for _, a := range reply.Answer {
if q.Name == a.Header().Name {
Expand Down

0 comments on commit 3e513ae

Please sign in to comment.