From 64a47d54c4e1775ea7305e4ed81bf0c5f49b3000 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 11 Aug 2008 08:19:48 +0000 Subject: [PATCH] Fix bug #947 (expire time overflow) --- ChangeLog | 4 ++++ configure.ac | 13 +++++++++++++ g10/ChangeLog | 5 +++++ g10/keygen.c | 18 ++++++++++++------ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c11418b7a..50e78f9a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-08-11 Werner Koch + + * configure.ac: Check for size of time_t. + 2008-04-01 Werner Koch * configure.ac (AC_INIT): Fix quoting. diff --git a/configure.ac b/configure.ac index f4c8bebe7..19afbaedb 100644 --- a/configure.ac +++ b/configure.ac @@ -949,6 +949,19 @@ AC_CHECK_SIZEOF(unsigned short) AC_CHECK_SIZEOF(unsigned int) AC_CHECK_SIZEOF(unsigned long) AC_CHECK_SIZEOF(unsigned long long) +AC_CHECK_SIZEOF(time_t,,[[ +#include +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif +]]) # Ensure that we have UINT64_C before we bother to check for uint64_t AC_CHECK_HEADERS([inttypes.h]) diff --git a/g10/ChangeLog b/g10/ChangeLog index b8f338b8f..0d9ba8c9c 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,8 @@ +2008-08-11 Werner Koch + + * keygen.c (ask_expire_interval): Check for time overflow of an + u32. Fixes bug #947. Use SIZEOF_TIME_T for the 2039--2106 check. + 2008-08-01 Werner Koch * tdbio.c (open_db) [!EROFS]: Move closing parens out of the diff --git a/g10/keygen.c b/g10/keygen.c index a74c9a2f2..9bc18777e 100644 --- a/g10/keygen.c +++ b/g10/keygen.c @@ -1697,12 +1697,18 @@ ask_expire_interval(u32 timestamp,int object,const char *def_expire) ? _("Key expires at %s\n") : _("Signature expires at %s\n"), asctimestamp((ulong)(timestamp + interval) ) ); - /* FIXME: This check yields warning on alhas: Write a - configure check and to this check here only for 32 bit - machines */ - if( (time_t)((ulong)(timestamp+interval)) < 0 ) - tty_printf(_("Your system can't display dates beyond 2038.\n" - "However, it will be correctly handled up to 2106.\n")); +#if SIZEOF_TIME_T <= 4 + if ((time_t)((ulong)(timestamp+interval)) < 0 ) + tty_printf (_("Your system can't display dates beyond 2038.\n" + "However, it will be correctly handled up to" + " 2106.\n")); + else +#endif /*SIZEOF_TIME_T*/ + if ( (time_t)((unsigned long)(timestamp+interval)) < timestamp ) + { + tty_printf (_("invalid value\n")); + continue; + } } if( cpr_enabled() || cpr_get_answer_is_yes("keygen.valid.okay",