mirror of
https://github.com/m13253/dns-over-https.git
synced 2024-09-21 15:57:11 +00:00
doh-client/google.go: [JSON-DOH] Fix DNS response empty []RR.Name
Cloudflare JSON DOH may return empty RR names if r.Question[0].Name is "." Which causes malformed DNS response
This commit is contained in:
parent
5f1f418664
commit
b30056a590
@ -157,6 +157,7 @@ func (c *Client) parseResponseGoogle(ctx context.Context, w dns.ResponseWriter,
|
||||
if respJSON.Status != dns.RcodeSuccess && respJSON.Comment != "" {
|
||||
log.Printf("DNS error: %s\n", respJSON.Comment)
|
||||
}
|
||||
fixEmptyNames(&respJSON)
|
||||
|
||||
fullReply := jsonDNS.Unmarshal(req.reply, &respJSON, req.udpSize, req.ednsClientNetmask)
|
||||
buf, err := fullReply.Pack()
|
||||
@ -177,3 +178,19 @@ func (c *Client) parseResponseGoogle(ctx context.Context, w dns.ResponseWriter,
|
||||
}
|
||||
w.Write(buf)
|
||||
}
|
||||
|
||||
// Fix DNS response empty []RR.Name
|
||||
// Additional section won't be rectified
|
||||
// see: https://stackoverflow.com/questions/52136176/what-is-additional-section-in-dns-and-how-it-works
|
||||
func fixEmptyNames(respJSON *jsonDNS.Response) {
|
||||
for i := range respJSON.Answer {
|
||||
if respJSON.Answer[i].Name == "" {
|
||||
respJSON.Answer[i].Name = "."
|
||||
}
|
||||
}
|
||||
for i := range respJSON.Authority {
|
||||
if respJSON.Authority[i].Name == "" {
|
||||
respJSON.Authority[i].Name = "."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user