From: Juergen Perlinger Date: Tue, 1 Mar 2016 07:30:22 +0000 (+0100) Subject: [Bug 3023] ntpdate cannot correct dates in the future. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a9c1cfa2494e51e39894bebe3a67ffd635b6ace;p=thirdparty%2Fntp.git [Bug 3023] ntpdate cannot correct dates in the future. bk: 56d5450ekhNG9y81GxG7ZyYK483rXw --- diff --git a/ChangeLog b/ChangeLog index c70fe8fc5..1eecb8c7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ * [Bug 2994] Systems with HAVE_SIGNALED_IO fail to compile. perlinger@ntp.org * [Bug 2995] Fixes to compile on Windows +* [Bug 3023] ntpdate cannot correct dates in the future. perlinger@ntp.org --- (4.2.8p6) 2016/01/20 Released by Harlan Stenn diff --git a/ntpdate/ntpdate.c b/ntpdate/ntpdate.c index a4271605c..be39cb030 100644 --- a/ntpdate/ntpdate.c +++ b/ntpdate/ntpdate.c @@ -1247,7 +1247,6 @@ static int clock_adjust(void) { register struct server *sp, *server; - s_fp absoffset; int dostep; for (sp = sys_servers; sp != NULL; sp = sp->next_server) @@ -1270,10 +1269,15 @@ clock_adjust(void) } else if (never_step) { dostep = 0; } else { - absoffset = server->soffset; - if (absoffset < 0) - absoffset = -absoffset; - dostep = (absoffset >= NTPDATE_THRESHOLD || absoffset < 0); + /* [Bug 3023] get absolute difference, avoiding signed + * integer overflow like hell. + */ + u_fp absoffset; + if (server->soffset < 0) + absoffset = 1u + (u_fp)(-(server->soffset + 1)); + else + absoffset = (u_fp)server->soffset; + dostep = (absoffset >= NTPDATE_THRESHOLD); } if (dostep) {