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:
Yong Tang
2026-06-23 16:02:35 -07:00
committed by GitHub
parent 67346401a2
commit fc447d0658
2 changed files with 119 additions and 0 deletions

View File

@@ -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