]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Fix UTI_DoubleToInt32 to check for overflow
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 5 Jun 2013 11:05:54 +0000 (13:05 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 5 Jun 2013 11:05:54 +0000 (13:05 +0200)
util.c

diff --git a/util.c b/util.c
index 6dbf67f2e37d68bc5c00071165bbde70342d6322..0861d739b50af8023e7fdfd1ca9d8b53563029a6 100644 (file)
--- a/util.c
+++ b/util.c
@@ -479,9 +479,15 @@ UTI_Int32ToDouble(NTP_int32 x)
 
 /* ================================================== */
 
+#define MAX_NTP_INT32 (4294967295.0 / 65536.0)
+
 NTP_int32
 UTI_DoubleToInt32(double x)
 {
+  if (x > MAX_NTP_INT32)
+    x = MAX_NTP_INT32;
+  else if (x < 0)
+    x = 0.0;
   return htonl((NTP_int32)(0.5 + 65536.0 * x));
 }