mirror of
https://github.com/coredns/coredns.git
synced 2026-07-10 17:50:12 -04:00
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:
@@ -128,6 +128,9 @@ func (t *Transfer) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
|
|||||||
batchSize := 0
|
batchSize := 0
|
||||||
var soa *dns.SOA
|
var soa *dns.SOA
|
||||||
for records := range pchan {
|
for records := range pchan {
|
||||||
|
if len(records) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if x, ok := records[0].(*dns.SOA); ok && soa == nil {
|
if x, ok := records[0].(*dns.SOA); ok && soa == nil {
|
||||||
soa = x
|
soa = x
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -474,3 +474,31 @@ func TestTransferLargeRecordBatching(t *testing.T) {
|
|||||||
t.Errorf("expected multiple messages for large transfer, got %d", len(w.Msgs))
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user