From: Christian Herdtweck Date: Thu, 30 Apr 2015 07:38:23 +0000 (+0200) Subject: fixed bug in TimeToLive: get huge TTLs from cast to uint32_t of negative values X-Git-Url: http://developer.intra2net.com/git/?p=pingcheck;a=commitdiff_plain;h=8bff33b430ff151afc54c7d2e0e2700b4be84652 fixed bug in TimeToLive: get huge TTLs from cast to uint32_t of negative values --- diff --git a/src/dns/timetolive.cpp b/src/dns/timetolive.cpp index 1497042..4d628eb 100644 --- a/src/dns/timetolive.cpp +++ b/src/dns/timetolive.cpp @@ -67,8 +67,10 @@ uint32_t TimeToLive::get_updated_value() const uint32_t elapsed_seconds = static_cast( (now - TtlSetTime).total_seconds() ); - uint32_t original_ttl = get_value(); - uint32_t remaining_seconds = original_ttl - elapsed_seconds; - return remaining_seconds; + uint32_t original_ttl = get_value(); + if (elapsed_seconds > original_ttl) + return 0; + else + return original_ttl - elapsed_seconds; } diff --git a/test/data/dns_cache_example.xml b/test/data/dns_cache_example.xml new file mode 100644 index 0000000..e3f61aa --- /dev/null +++ b/test/data/dns_cache_example.xml @@ -0,0 +1,88 @@ + + + + + 4 + 0 + + abc.xyz + + 1 + 0 + + 11.22.33.44 + + 567 + 20150429T140512.609565 + + + + + + cname1.xyz + + 0 + 0 + + + + cname2.xyz + + 0 + 0 + + + + cname3.xyz + + 0 + 0 + + + + + 4 + 0 + + abc.xyz + + + + 0 + 20150429T131654.312043 + + + + + cname1.xyz + + abc.xyz + + 27 + 20150429T140512.609555 + + + + + cname2.xyz + + cname1.xyz + + 207 + 20150429T140512.609545 + + + + + cname3.xyz + + cname2.xyz + + 87 + 20150429T140512.609533 + + + + + +