plugin/transfer: Fix panic in CoreDNS transfer plugin caused by empty DNS record (#8207)

This PR fixes panic in CoreDNS transfer plugin caused by empty DNS record.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang
2026-07-09 10:21:45 -07:00
committed by GitHub
parent 2d106be341
commit ab318db7b4
2 changed files with 31 additions and 0 deletions

View File

@@ -128,6 +128,9 @@ func (t *Transfer) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
batchSize := 0
var soa *dns.SOA
for records := range pchan {
if len(records) == 0 {
continue
}
if x, ok := records[0].(*dns.SOA); ok && soa == nil {
soa = x
}

View File

@@ -474,3 +474,31 @@ func TestTransferLargeRecordBatching(t *testing.T) {
t.Errorf("expected multiple messages for large transfer, got %d", len(w.Msgs))
}
}
type emptyBatchTransferer struct{}
func (emptyBatchTransferer) Transfer(_ string, _ uint32) (<-chan []dns.RR, error) {
ch := make(chan []dns.RR, 1)
ch <- []dns.RR{}
close(ch)
return ch, nil
}
func TestTransferEmptyBatch(t *testing.T) {
tr := &Transfer{
Transferers: []Transferer{emptyBatchTransferer{}},
xfrs: []*xfr{{Zones: []string{"example.org."}, to: []string{"*"}}},
}
req := new(dns.Msg)
req.SetQuestion("example.org.", dns.TypeAXFR)
rec := dnstest.NewRecorder(&test.ResponseWriter{TCP: true})
_, err := tr.ServeDNS(context.Background(), rec, req)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}