git » debian:dnss » commit 4094141

dnstox: Set the question explicitly on the httpsResolver's reply

author Alberto Bertogli
2016-05-29 21:04:23 UTC
committer Alberto Bertogli
2016-05-29 21:09:34 UTC
parent 45365baa5a9aa19dc6702a6357679d7ffcccb2ea

dnstox: Set the question explicitly on the httpsResolver's reply

The current httpsResolver uses dns.Msg.SetQuestion to set the question on the
reply, but it's wrong as the code also sets the id, and sets the recursion
desired bit (it's intended to construct requests, not replies).

This patch fixes that by setting the question directly.

Thanks to Rodrigo Campos for the bug report!

internal/dnstox/resolver.go +10 -5

diff --git a/internal/dnstox/resolver.go b/internal/dnstox/resolver.go
index a90326b..367f6cd 100644
--- a/internal/dnstox/resolver.go
+++ b/internal/dnstox/resolver.go
@@ -227,6 +227,10 @@ func (r *httpsResolver) Query(req *dns.Msg, tr trace.Trace) (*dns.Msg, error) {
 		return nil, fmt.Errorf("Failed to unmarshall: %v", err)
 	}
 
+	if len(jr.Question) != 1 {
+		return nil, fmt.Errorf("Wrong number of questions in the response")
+	}
+
 	// Build the DNS response.
 	resp := &dns.Msg{
 		MsgHdr: dns.MsgHdr{
@@ -241,13 +245,14 @@ func (r *httpsResolver) Query(req *dns.Msg, tr trace.Trace) (*dns.Msg, error) {
 			AuthenticatedData:  jr.AD,
 			CheckingDisabled:   jr.CD,
 		},
+		Question: []dns.Question{
+			dns.Question{
+				Name:   jr.Question[0].Name,
+				Qtype:  jr.Question[0].Type,
+				Qclass: dns.ClassINET,
+			}},
 	}
 
-	if len(jr.Question) != 1 {
-		return nil, fmt.Errorf("Wrong number of questions in the response")
-	}
-	resp.SetQuestion(jr.Question[0].Name, jr.Question[0].Type)
-
 	for _, answer := range jr.Answer {
 		// TODO: This "works" but is quite hacky. Is there a better way,
 		// without doing lots of data parsing?