From: Timo Sirainen Date: Sat, 2 Aug 2003 17:38:15 +0000 (+0300) Subject: utc_mktime() crashed with 64bit time_t if gmtime() didn't like >32bit values X-Git-Tag: 1.1.alpha1~4448 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4510b57951cdedca279ae838cd42c21069393a72;p=thirdparty%2Fdovecot%2Fcore.git utc_mktime() crashed with 64bit time_t if gmtime() didn't like >32bit values --HG-- branch : HEAD --- diff --git a/configure.in b/configure.in index 861423aa18..f1e8e5131e 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ AC_INIT(src) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(dovecot, 0.99.10) +AM_INIT_AUTOMAKE(dovecot, 0.99.11-test4) AM_MAINTAINER_MODE @@ -536,6 +536,41 @@ if test $i_cv_field_tm_gmtoff = yes; then fi AC_MSG_RESULT($i_cv_field_tm_gmtoff) +dnl * how large time_t values does gmtime() accept? +AC_MSG_CHECKING([how large time_t values gmtime() accepts]) +AC_TRY_RUN([ + #include + #include + int main() { + FILE *f; + int bits; + time_t t; + + for (bits = 1, t = 1; t > 0; ++bits, t <<= 1) { + if (gmtime(&t) == NULL) { + bits--; + break; + } + } + f = fopen("conftest.temp", "w"); + if (f == NULL) { + perror("fopen()"); + return 1; + } + fprintf(f, "%d", bits); + fclose(f); + return 0; + } +], [ + max_bits=`cat conftest.temp` + rm -f conftest.temp + AC_MSG_RESULT($max_bits) +], [ + AC_MSG_RESULT([check failed, assuming 31]) + max_bits=31 +]) +AC_DEFINE_UNQUOTED(TIME_T_MAX_BITS, $max_bits, max. time_t bits gmtime() can handle) + dnl * do we have struct iovec AC_MSG_CHECKING([for struct iovec]) AC_CACHE_VAL(i_cv_struct_iovec, diff --git a/src/lib/utc-mktime.c b/src/lib/utc-mktime.c index 7132c53354..9ee7ad56d3 100644 --- a/src/lib/utc-mktime.c +++ b/src/lib/utc-mktime.c @@ -84,6 +84,7 @@ ** would still be very reasonable). */ +#include "lib.h" #include "utc-mktime.h" static int tmcomp(register const struct tm * const atmp, @@ -116,8 +117,9 @@ time_t utc_mktime(struct tm *tm) ** (this works regardless of whether time_t is ** signed or unsigned, though lint complains if unsigned). */ - for (bits = 0, t = 1; t > 0; ++bits, t <<= 1) - ; + for (bits = 0, t = 1; t > 0 && bits < TIME_T_MAX_BITS-1; bits++) + t <<= 1; + /* ** If time_t is signed, then 0 is the median value, ** if time_t is unsigned, then 1 << bits is median.