From: Dave Hart Date: Thu, 20 Jan 2011 08:27:32 +0000 (+0000) Subject: Change new timeval and timespec to string routines to use snprintf() X-Git-Tag: NTP_4_2_7P120~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc088082b1f122f4451c2105dff93f322dec8927;p=thirdparty%2Fntp.git Change new timeval and timespec to string routines to use snprintf() rather than hand-crafted conversion, avoid signed int overflow there. Add configure support for SIZEOF_LONG_LONG to enable portable use of snprintf() with time_t. bk: 4d37f1f4gpu7tDOPSbW-bC83_nxKtg --- diff --git a/ChangeLog b/ChangeLog index 649255902..aed39f67e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ -* changed timeval / timespec string conversion (snprintf() format - strings for time_t vs. int / long / long long; avoid signed integer - overflow) +* Change new timeval and timespec to string routines to use snprintf() + rather than hand-crafted conversion, avoid signed int overflow there. +* Add configure support for SIZEOF_LONG_LONG to enable portable use of + snprintf() with time_t. * Grow ntpd/work_thread.c arrays as needed. * Add DEBUG_* variants of ntp_assert.h macros which compile away using ./configure --disable-debugging. diff --git a/configure.ac b/configure.ac index e3015c83e..a447bde39 100644 --- a/configure.ac +++ b/configure.ac @@ -415,7 +415,6 @@ AC_EGREP_CPP( )] ) AC_CHECK_HEADERS([sys/timers.h sys/tpro.h sys/types.h sys/wait.h]) -AC_HEADER_TIME case "$host" in *-convex-*) AC_CHECK_HEADERS([/sys/sync/queue.h /sys/sync/sema.h]) @@ -933,49 +932,6 @@ AC_CHECK_MEMBERS( ] ) -AC_C_INLINE - -case "$ac_cv_c_inline" in - '') - ;; - *) - AC_DEFINE([HAVE_INLINE], [1], [inline keyword or macro available]) - AC_SUBST([HAVE_INLINE]) -esac - -AC_C_CHAR_UNSIGNED dnl CROSS_COMPILE? -AC_CHECK_SIZEOF([signed char]) -AC_CHECK_TYPES([s_char]) -AC_CHECK_SIZEOF([short]) -AC_CHECK_SIZEOF([int]) -AC_CHECK_SIZEOF([long]) - -case "$ac_cv_c_char_unsigned$ac_cv_sizeof_signed_char$ac_cv_type_s_char" in - *yes) - # We have a typedef for s_char. Might as well believe it... - ;; - no0no) - # We have signed chars, can't say 'signed char', no s_char typedef. - AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1], - [Do we need an s_char typedef?]) - ;; - no1no) - # We have signed chars, can say 'signed char', no s_char typedef. - AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1], - [Do we need an s_char typedef?]) - ;; - yes0no) - # We have unsigned chars, can't say 'signed char', no s_char typedef. - AC_MSG_ERROR([No way to specify a signed character!]) - ;; - yes1no) - # We have unsigned chars, can say 'signed char', no s_char typedef. - AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1], - [Do we need an s_char typedef?]) - ;; -esac -AC_TYPE_UID_T - case "$host" in *-*-aix[[456]]*) # (prr) aix 4.1 doesn't have clock_settime, but in aix 4.3 it's a stub diff --git a/libntp/timespecops.c b/libntp/timespecops.c index 849fd3964..0fd53d37c 100644 --- a/libntp/timespecops.c +++ b/libntp/timespecops.c @@ -47,11 +47,11 @@ typedef unsigned int u_time; #elif SIZEOF_TIME_T <= SIZEOF_LONG typedef unsigned long u_time; #define TIMEFMT "l" -#elif SIZEOF_TIME_T <= SIZEOF_LONG_LONG +#elif defined(SIZEOF_LONG_LONG) && SIZEOF_TIME_T <= SIZEOF_LONG_LONG typedef unsigned long long u_time; #define TIMEFMT "ll" #else -# include "GRONK: what size has a time_t here?" +#include "GRONK: what size has a time_t here?" #endif diff --git a/libntp/timevalops.c b/libntp/timevalops.c index 4699a9c16..623c2f978 100644 --- a/libntp/timevalops.c +++ b/libntp/timevalops.c @@ -45,11 +45,11 @@ typedef unsigned int u_time; #elif SIZEOF_TIME_T <= SIZEOF_LONG typedef unsigned long u_time; #define TIMEFMT "l" -#elif SIZEOF_TIME_T <= SIZEOF_LONG_LONG +#elif defined(SIZEOF_LONG_LONG) && SIZEOF_TIME_T <= SIZEOF_LONG_LONG typedef unsigned long long u_time; #define TIMEFMT "ll" #else -# include "GRONK: what size has a time_t here?" +#include "GRONK: what size has a time_t here?" #endif /* copy and normalise. Used often enough to warrant a macro. */ diff --git a/ports/winnt/include/config.h b/ports/winnt/include/config.h index 8491b01a4..3f087cc96 100644 --- a/ports/winnt/include/config.h +++ b/ports/winnt/include/config.h @@ -361,7 +361,9 @@ typedef __int32 int32_t; /* define a typedef for int32_t */ # define SIZEOF_SIGNED_CHAR 1 # define SIZEOF_SHORT 2 -# define SIZEOF_INT 4 /* for ntp_types.h */ +# define SIZEOF_INT 4 +# define SIZEOF_LONG 4 +# define SIZEOF_LONG_LONG 8 # define HAVE_ALLOCA # define HAVE_SETVBUF diff --git a/sntp/configure.ac b/sntp/configure.ac index 875d504d0..7984857d4 100644 --- a/sntp/configure.ac +++ b/sntp/configure.ac @@ -101,53 +101,11 @@ AC_HEADER_STDC AC_CHECK_HEADERS([netdb.h netinet/in.h stdlib.h string.h strings.h syslog.h]) AC_CHECK_HEADERS([sys/time.h]) -AC_HEADER_TIME # Checks for typedefs, structures, and compiler characteristics. AC_HEADER_STDBOOL AC_C_CONST AC_TYPE_SIZE_T -AC_CHECK_SIZEOF([time_t]) - -AC_C_INLINE - -case "$ac_cv_c_inline" in - '') - ;; - *) - AC_DEFINE(HAVE_INLINE,1,[inline keyword or macro available]) - AC_SUBST(HAVE_INLINE) -esac - -AC_C_CHAR_UNSIGNED dnl CROSS_COMPILE? -AC_CHECK_SIZEOF([signed char]) -AC_CHECK_SIZEOF([short]) -AC_CHECK_SIZEOF([int]) -AC_CHECK_SIZEOF([long]) - -AC_CHECK_TYPES([s_char]) -case "$ac_cv_c_char_unsigned$ac_cv_sizeof_signed_char$ac_cv_type_s_char" in - *yes) - # We have a typedef for s_char. Might as well believe it... - ;; - no0no) - # We have signed chars, can't say 'signed char', no s_char typedef. - AC_DEFINE([NEED_S_CHAR_TYPEDEF], 1, [Do we need an s_char typedef?]) - ;; - no1no) - # We have signed chars, can say 'signed char', no s_char typedef. - AC_DEFINE([NEED_S_CHAR_TYPEDEF]) - ;; - yes0no) - # We have unsigned chars, can't say 'signed char', no s_char typedef. - AC_MSG_ERROR([No way to specify a signed character!]) - ;; - yes1no) - # We have unsigned chars, can say 'signed char', no s_char typedef. - AC_DEFINE([NEED_S_CHAR_TYPEDEF]) - ;; -esac -AC_TYPE_UID_T NTP_OPENSSL NTP_IPV6 diff --git a/sntp/m4/ntp_libntp.m4 b/sntp/m4/ntp_libntp.m4 index 044747597..c381f3a1c 100644 --- a/sntp/m4/ntp_libntp.m4 +++ b/sntp/m4/ntp_libntp.m4 @@ -252,6 +252,59 @@ case "$ac_cv_search_setsockopt" in esac AS_UNSET([saved_LIBS]) +AC_C_INLINE + +case "$ac_cv_c_inline" in + '') + ;; + *) + AC_DEFINE([HAVE_INLINE], [1], [inline keyword or macro available]) + AC_SUBST([HAVE_INLINE]) +esac + +AC_HEADER_TIME +AC_CHECK_SIZEOF([time_t]) +AC_C_CHAR_UNSIGNED dnl CROSS_COMPILE? +AC_CHECK_SIZEOF([signed char]) +AC_CHECK_TYPES([s_char, long long]) +AC_CHECK_SIZEOF([short]) +AC_CHECK_SIZEOF([int]) +AC_CHECK_SIZEOF([long]) + +case "$ac_cv_type_long_long" in + no) + ;; + *) + AC_CHECK_SIZEOF([long long]) + ;; +esac + +case "$ac_cv_c_char_unsigned$ac_cv_sizeof_signed_char$ac_cv_type_s_char" in + *yes) + # We have a typedef for s_char. Might as well believe it... + ;; + no0no) + # We have signed chars, can't say 'signed char', no s_char typedef. + AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1], + [Do we need an s_char typedef?]) + ;; + no1no) + # We have signed chars, can say 'signed char', no s_char typedef. + AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1], + [Do we need an s_char typedef?]) + ;; + yes0no) + # We have unsigned chars, can't say 'signed char', no s_char typedef. + AC_MSG_ERROR([No way to specify a signed character!]) + ;; + yes1no) + # We have unsigned chars, can say 'signed char', no s_char typedef. + AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1], + [Do we need an s_char typedef?]) + ;; +esac + +AC_TYPE_UID_T AC_FUNC_STRERROR_R dnl preset withsntp=no in env to change default to --without-sntp