From: Miroslav Lichvar Date: Wed, 5 Jun 2013 11:05:54 +0000 (+0200) Subject: Fix UTI_DoubleToInt32 to check for overflow X-Git-Tag: 1.28-pre1~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8eb7ce85815c9040fbcfb30266d7875207956516;p=thirdparty%2Fchrony.git Fix UTI_DoubleToInt32 to check for overflow --- diff --git a/util.c b/util.c index 6dbf67f2..0861d739 100644 --- 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)); }