1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #1125 from sanimej/bugs

Fix a panic in handling forwarded queries
This commit is contained in:
Jana Radhakrishnan 2016-04-22 08:57:32 -07:00
commit 4d59574cb3

View file

@ -292,6 +292,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
extConn net.Conn extConn net.Conn
resp *dns.Msg resp *dns.Msg
err error err error
writer dns.ResponseWriter
) )
if query == nil || len(query.Question) == 0 { if query == nil || len(query.Question) == 0 {
@ -329,7 +330,9 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
if resp.Len() > maxSize { if resp.Len() > maxSize {
truncateResp(resp, maxSize, proto == "tcp") truncateResp(resp, maxSize, proto == "tcp")
} }
writer = w
} else { } else {
queryID := query.Id
for i := 0; i < maxExtDNS; i++ { for i := 0; i < maxExtDNS; i++ {
extDNS := &r.extDNSList[i] extDNS := &r.extDNSList[i]
if extDNS.ipStr == "" { if extDNS.ipStr == "" {
@ -375,7 +378,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
// forwardQueryStart stores required context to mux multiple client queries over // forwardQueryStart stores required context to mux multiple client queries over
// one connection; and limits the number of outstanding concurrent queries. // one connection; and limits the number of outstanding concurrent queries.
if r.forwardQueryStart(w, query) == false { if r.forwardQueryStart(w, query, queryID) == false {
old := r.tStamp old := r.tStamp
r.tStamp = time.Now() r.tStamp = time.Now()
if r.tStamp.Sub(old) > logInterval { if r.tStamp.Sub(old) > logInterval {
@ -405,32 +408,33 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
// Retrieves the context for the forwarded query and returns the client connection // Retrieves the context for the forwarded query and returns the client connection
// to send the reply to // to send the reply to
w = r.forwardQueryEnd(w, resp) writer = r.forwardQueryEnd(w, resp)
if w == nil { if writer == nil {
continue continue
} }
resp.Compress = true resp.Compress = true
break break
} }
if resp == nil || writer == nil {
if resp == nil || w == nil {
return return
} }
} }
err = w.WriteMsg(resp) if writer == nil {
if err != nil { return
}
if err = writer.WriteMsg(resp); err != nil {
log.Errorf("error writing resolver resp, %s", err) log.Errorf("error writing resolver resp, %s", err)
} }
} }
func (r *resolver) forwardQueryStart(w dns.ResponseWriter, msg *dns.Msg) bool { func (r *resolver) forwardQueryStart(w dns.ResponseWriter, msg *dns.Msg, queryID uint16) bool {
proto := w.LocalAddr().Network() proto := w.LocalAddr().Network()
dnsID := uint16(rand.Intn(maxDNSID)) dnsID := uint16(rand.Intn(maxDNSID))
cc := clientConn{ cc := clientConn{
dnsID: msg.Id, dnsID: queryID,
respWriter: w, respWriter: w,
} }