]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
utc_mktime() crashed with 64bit time_t if gmtime() didn't like >32bit values
authorTimo Sirainen <tss@iki.fi>
Sat, 2 Aug 2003 17:38:15 +0000 (20:38 +0300)
committerTimo Sirainen <tss@iki.fi>
Sat, 2 Aug 2003 17:38:15 +0000 (20:38 +0300)
--HG--
branch : HEAD

configure.in
src/lib/utc-mktime.c

index 861423aa18c8a16d6c5fcd0e1baab50528899323..f1e8e5131e956237b63f1581dc223b827337909e 100644 (file)
@@ -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 <stdio.h>
+  #include <time.h>
+  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,
index 7132c53354c28934d9c7531f59c8c10d138e791d..9ee7ad56d3b0a9568431acc36fb3c15ef1308415 100644 (file)
@@ -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.