1
0
mirror of https://github.com/DNSCrypt/dnscrypt-proxy.git synced 2024-12-29 00:30:30 +01:00

fix: updateTTL guard against overflow

This commit is contained in:
Markus Linnala 2019-10-17 15:17:03 +03:00 committed by Frank Denis
parent 13e9c15212
commit 63520e494d

View File

@ -166,8 +166,11 @@ func setMaxTTL(msg *dns.Msg, ttl uint32) {
}
func updateTTL(msg *dns.Msg, expiration time.Time) {
ttl := uint32(time.Until(expiration) / time.Second)
until := time.Until(expiration)
ttl := uint32(0)
if until > 0 {
ttl = uint32(until / time.Second)
}
for _, rr := range msg.Answer {
rr.Header().Ttl = ttl
}
@ -175,10 +178,8 @@ func updateTTL(msg *dns.Msg, expiration time.Time) {
rr.Header().Ttl = ttl
}
for _, rr := range msg.Extra {
header := rr.Header()
if header.Rrtype == dns.TypeOPT {
continue
if rr.Header().Rrtype != dns.TypeOPT {
rr.Header().Ttl = ttl
}
rr.Header().Ttl = ttl
}
}