fixed bug in TimeToLive: get huge TTLs from cast to uint32_t of negative values
[pingcheck] / src / dns / timetolive.cpp
index 1497042..4d628eb 100644 (file)
@@ -67,8 +67,10 @@ uint32_t TimeToLive::get_updated_value() const
     uint32_t elapsed_seconds = static_cast<uint32_t>(
             (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;
 }