fix(cache): data race when updating the TTL of cached messages (#7397)

This commit is contained in:
Sebastian Mayr
2025-07-03 04:20:47 +02:00
committed by GitHub
parent e34fda5d46
commit 06da7dcd98

View File

@@ -3,8 +3,8 @@ package cache
import "github.com/miekg/dns"
// filterRRSlice filters out OPT RRs, and sets all RR TTLs to ttl.
// If dup is true the RRs in rrs are _copied_ into the slice that is
// returned.
// If dup is true the RRs in rrs are _copied_ before adjusting their
// TTL and the slice of copied RRs is returned.
func filterRRSlice(rrs []dns.RR, ttl uint32, dup bool) []dns.RR {
j := 0
rs := make([]dns.RR, len(rrs))
@@ -12,12 +12,12 @@ func filterRRSlice(rrs []dns.RR, ttl uint32, dup bool) []dns.RR {
if r.Header().Rrtype == dns.TypeOPT {
continue
}
r.Header().Ttl = ttl
if dup {
rs[j] = dns.Copy(r)
} else {
rs[j] = r
}
rs[j].Header().Ttl = ttl
j++
}
return rs[:j]