mirror of
https://github.com/coredns/coredns.git
synced 2026-10-16 15:25:47 -04:00
plugin/autopath: Fixes a nil pointer dereference panic in autopath during search path walk (#8517)
* plugin/autopath: Fixes a nil pointer dereference panic in autopath during search path walk When a plugin later in the chain returns a ClientWrite rcode without writing a response (for example acl's drop action, which returns (dns.RcodeSuccess, nil) without calling WriteMsg), autopath dereferences a nil nw.Msg at nw.Msg.Rcode and panics. The final fallback w.WriteMsg(firstReply) can also receive a nil firstReply for the same reason. Skip search path elements that produced no message, and only write the first reply when it is non-nil. This mirrors the nil guards recently added in plugin/minimal (#8506), plugin/dns64 (#8511) and plugin/cache (#8512). Signed-off-by: zjncs <18910855655@163.com> * plugin/autopath: silence unused-parameter lint and assert no client write Address review feedback on #8517: rename the unused 'w' parameter in TestAutoPathNilMsgFromNext to '_w' so the revive unused-parameter check passes, and assert that the recorder receives no message so the intended drop/no-client-write behavior is explicit. Signed-off-by: zjncs <18910855655@163.com> --------- Signed-off-by: zjncs <18910855655@163.com>
This commit is contained in:
@@ -123,6 +123,10 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
|
||||
continue
|
||||
}
|
||||
|
||||
if nw.Msg == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if nw.Msg.Rcode == dns.RcodeNameError {
|
||||
continue
|
||||
}
|
||||
@@ -135,7 +139,7 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
|
||||
autoPathCount.WithLabelValues(metrics.WithServer(ctx)).Add(1)
|
||||
return rcode, err
|
||||
}
|
||||
if plugin.ClientWrite(firstRcode) {
|
||||
if plugin.ClientWrite(firstRcode) && firstReply != nil {
|
||||
w.WriteMsg(firstReply)
|
||||
}
|
||||
return firstRcode, firstErr
|
||||
|
||||
Reference in New Issue
Block a user