mirror of
https://github.com/coredns/coredns.git
synced 2026-07-15 12:10:11 -04:00
plugin/rewrite: Fix nil-pointer panic in EDNS0 response reversion with no OPT record (#8190)
* plugin/rewrite: Fix nil-pointer panic in EDNS0 response reversion with no OPT record This PR fix a nil-pointer panic in EDNS0 response reversion when downstream responses do not contain an OPT record, Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * Fix Signed-off-by: Yong Tang <yong.tang.github@outlook.com> --------- Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -46,6 +46,9 @@ type edns0SetResponseRule struct {
|
||||
|
||||
func (r *edns0SetResponseRule) RewriteResponse(res *dns.Msg, _ dns.RR) {
|
||||
ednsOpt := res.IsEdns0()
|
||||
if ednsOpt == nil {
|
||||
return
|
||||
}
|
||||
for idx, opt := range ednsOpt.Option {
|
||||
if opt.Option() == r.code {
|
||||
ednsOpt.Option = append(ednsOpt.Option[:idx], ednsOpt.Option[idx+1:]...)
|
||||
@@ -61,6 +64,9 @@ type edns0ReplaceResponseRule[T dns.EDNS0] struct {
|
||||
|
||||
func (r *edns0ReplaceResponseRule[T]) RewriteResponse(res *dns.Msg, _ dns.RR) {
|
||||
ednsOpt := res.IsEdns0()
|
||||
if ednsOpt == nil {
|
||||
return
|
||||
}
|
||||
for idx, opt := range ednsOpt.Option {
|
||||
if opt.Option() == r.code {
|
||||
ednsOpt.Option[idx] = r.source
|
||||
|
||||
Reference in New Issue
Block a user