diff options
author | 2019-02-25 19:16:17 +0300 | |
---|---|---|
committer | 2019-02-25 16:16:17 +0000 | |
commit | 2b6fb578c3d9689461040881ed2e41aa91d1e319 (patch) | |
tree | 328608e49580a4a2b8b904b229732d8edf58d9fe | |
parent | 47cce40d199e320e8a36348a3b664aa998856976 (diff) | |
download | coredns-2b6fb578c3d9689461040881ed2e41aa91d1e319.tar.gz coredns-2b6fb578c3d9689461040881ed2e41aa91d1e319.tar.zst coredns-2b6fb578c3d9689461040881ed2e41aa91d1e319.zip |
DoH: Fixing panic in case if there's no response (#2577)
* Fixing panic in case if there's no response
There could be a situation when there's no response after ServeDNS call. With the current implementation, this leads to panic.
* Add comment
-rw-r--r-- | core/dnsserver/server_https.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/core/dnsserver/server_https.go b/core/dnsserver/server_https.go index 1e184e044..6ae6ce6a6 100644 --- a/core/dnsserver/server_https.go +++ b/core/dnsserver/server_https.go @@ -119,6 +119,14 @@ func (s *ServerHTTPS) ServeHTTP(w http.ResponseWriter, r *http.Request) { // We should expect a packet to be returned that we can send to the client. s.ServeDNS(context.Background(), dw, msg) + // See section 4.2.1 of RFC 8484. + // We are using code 500 to indicate an unexpected situation when the chain + // handler has not provided any response message. + if dw.Msg == nil { + http.Error(w, "No response", http.StatusInternalServerError) + return + } + buf, _ := dw.Msg.Pack() mt, _ := response.Typify(dw.Msg, time.Now().UTC()) |