From d8e323e18615bccacf433340944e007f9ed5a9f1 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 31 Jul 2017 18:49:36 -0700 Subject: [PATCH] Rename 2038 epoch check to something more accurate & less alarming than 'TimeBombExploded' (sheesh), and only bother with it if time_t is 32 bits. --- config.h.in | 3 +++ configure | 33 +++++++++++++++++++++++++ configure.ac | 1 + src/core/Makefile.am | 10 ++++---- src/core/Makefile.in | 20 ++++++++-------- src/core/{timebomb.cpp => epoch.cpp} | 36 +++++++--------------------- src/core/{timebomb.h => epoch.h} | 10 ++++---- src/siggen/siggenmain.cpp | 4 ++-- src/tripwire/tripwiremain.cpp | 4 ++-- src/twadmin/twadminmain.cpp | 4 ++-- src/twprint/twprintmain.cpp | 4 ++-- 11 files changed, 73 insertions(+), 56 deletions(-) rename src/core/{timebomb.cpp => epoch.cpp} (74%) rename src/core/{timebomb.h => epoch.h} (91%) diff --git a/config.h.in b/config.h.in index 5c22894..f7c8937 100644 --- a/config.h.in +++ b/config.h.in @@ -174,6 +174,9 @@ /* The size of `long long', as computed by sizeof. */ #undef SIZEOF_LONG_LONG +/* The size of `time_t', as computed by sizeof. */ +#undef SIZEOF_TIME_T + /* Don't use gethostbyname() on Solaris */ #undef SOLARIS_NO_GETHOSTBYNAME diff --git a/configure b/configure index 8311cc7..3052a28 100755 --- a/configure +++ b/configure @@ -6058,6 +6058,39 @@ cat >>confdefs.h <<_ACEOF _ACEOF +# The cast to long int works around a bug in the HP C Compiler +# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects +# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. +# This bug is HP SR number 8606223364. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of time_t" >&5 +$as_echo_n "checking size of time_t... " >&6; } +if ${ac_cv_sizeof_time_t+:} false; then : + $as_echo_n "(cached) " >&6 +else + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (time_t))" "ac_cv_sizeof_time_t" "$ac_includes_default"; then : + +else + if test "$ac_cv_type_time_t" = yes; then + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "cannot compute sizeof (time_t) +See \`config.log' for more details" "$LINENO" 5; } + else + ac_cv_sizeof_time_t=0 + fi +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_time_t" >&5 +$as_echo "$ac_cv_sizeof_time_t" >&6; } + + + +cat >>confdefs.h <<_ACEOF +#define SIZEOF_TIME_T $ac_cv_sizeof_time_t +_ACEOF + + $as_echo "#define USES_1S_COMPLEMENT 0" >>confdefs.h diff --git a/configure.ac b/configure.ac index b076cc8..f5a55ca 100644 --- a/configure.ac +++ b/configure.ac @@ -99,6 +99,7 @@ AC_C_BIGENDIAN AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(long long) +AC_CHECK_SIZEOF(time_t) dnl All platforms we support use 2's complement, are byte aligned, etc... AC_DEFINE(USES_1S_COMPLEMENT, 0, [Uses one's complement]) diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 484e642..0a47f0e 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -9,25 +9,25 @@ libcore_a_SOURCES = \ archive.cpp charutil.cpp \ cmdlineparser.cpp codeconvert.cpp core.cpp coreerrors.cpp \ corestrings.cpp crc32.cpp debug.cpp displayencoder.cpp \ - displayutil.cpp error.cpp errorbucketimpl.cpp errortable.cpp \ + displayutil.cpp epoch.cpp error.cpp errorbucketimpl.cpp errortable.cpp \ errorutil.cpp fileerror.cpp fileheader.cpp fsservices.cpp \ growheap.cpp hashtable.cpp haval.cpp msystem.cpp ntmbs.cpp \ refcountobj.cpp serializable.cpp serializer.cpp \ serializerimpl.cpp serializerutil.cpp serstring.cpp \ srefcountobj.cpp srefcounttbl.cpp stdcore.cpp stringutil.cpp \ - timebomb.cpp timeconvert.cpp tw_signal.cpp twlimits.cpp twlocale.cpp \ + timeconvert.cpp tw_signal.cpp twlimits.cpp twlocale.cpp \ unixexcept.cpp usernotify.cpp usernotifystdout.cpp \ wchar16.cpp libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \ core.h coreerrors.h corestrings.h crc32.h debug.h displayencoder.h \ - displayutil.h error.h errorbucket.h errorbucketimpl.h errorgeneral.h \ + displayutil.h epoch.h error.h errorbucket.h errorbucketimpl.h errorgeneral.h \ errortable.h errorutil.h file.h fileerror.h fileheader.h fixedfilebuf.h \ fsservices.h growheap.h hashtable.h haval.h md5.h msystem.h ntdbs.h \ - ntmbs.h package.h platform.h refcountobj.h resources.h \ + ntmbs.h package.h platform.h refcountobj.h resources.h \ serializable.h serializer.h serializerimpl.h serializerutil.h serstring.h \ sha.h srefcountobj.h srefcounttbl.h stdcore.h stringutil.h tasktimer.h \ - tchar.h timebomb.h timeconvert.h tw_signal.h twlimits.h twlocale.h \ + tchar.h timeconvert.h tw_signal.h twlimits.h twlocale.h \ twstringslang.h typed.h types.h unixexcept.h unixfsservices.h upperbound.h \ usernotify.h usernotifystdout.h wchar16.h diff --git a/src/core/Makefile.in b/src/core/Makefile.in index 858721f..694e8f0 100644 --- a/src/core/Makefile.in +++ b/src/core/Makefile.in @@ -113,8 +113,8 @@ am_libcore_a_OBJECTS = file_unix.$(OBJEXT) unixfsservices.$(OBJEXT) \ archive.$(OBJEXT) charutil.$(OBJEXT) cmdlineparser.$(OBJEXT) \ codeconvert.$(OBJEXT) core.$(OBJEXT) coreerrors.$(OBJEXT) \ corestrings.$(OBJEXT) crc32.$(OBJEXT) debug.$(OBJEXT) \ - displayencoder.$(OBJEXT) displayutil.$(OBJEXT) error.$(OBJEXT) \ - errorbucketimpl.$(OBJEXT) errortable.$(OBJEXT) \ + displayencoder.$(OBJEXT) displayutil.$(OBJEXT) epoch.$(OBJEXT) \ + error.$(OBJEXT) errorbucketimpl.$(OBJEXT) errortable.$(OBJEXT) \ errorutil.$(OBJEXT) fileerror.$(OBJEXT) fileheader.$(OBJEXT) \ fsservices.$(OBJEXT) growheap.$(OBJEXT) hashtable.$(OBJEXT) \ haval.$(OBJEXT) msystem.$(OBJEXT) ntmbs.$(OBJEXT) \ @@ -122,9 +122,9 @@ am_libcore_a_OBJECTS = file_unix.$(OBJEXT) unixfsservices.$(OBJEXT) \ serializer.$(OBJEXT) serializerimpl.$(OBJEXT) \ serializerutil.$(OBJEXT) serstring.$(OBJEXT) \ srefcountobj.$(OBJEXT) srefcounttbl.$(OBJEXT) \ - stdcore.$(OBJEXT) stringutil.$(OBJEXT) timebomb.$(OBJEXT) \ - timeconvert.$(OBJEXT) tw_signal.$(OBJEXT) twlimits.$(OBJEXT) \ - twlocale.$(OBJEXT) unixexcept.$(OBJEXT) usernotify.$(OBJEXT) \ + stdcore.$(OBJEXT) stringutil.$(OBJEXT) timeconvert.$(OBJEXT) \ + tw_signal.$(OBJEXT) twlimits.$(OBJEXT) twlocale.$(OBJEXT) \ + unixexcept.$(OBJEXT) usernotify.$(OBJEXT) \ usernotifystdout.$(OBJEXT) wchar16.$(OBJEXT) libcore_a_OBJECTS = $(am_libcore_a_OBJECTS) AM_V_P = $(am__v_P_@AM_V@) @@ -334,25 +334,25 @@ libcore_a_SOURCES = \ archive.cpp charutil.cpp \ cmdlineparser.cpp codeconvert.cpp core.cpp coreerrors.cpp \ corestrings.cpp crc32.cpp debug.cpp displayencoder.cpp \ - displayutil.cpp error.cpp errorbucketimpl.cpp errortable.cpp \ + displayutil.cpp epoch.cpp error.cpp errorbucketimpl.cpp errortable.cpp \ errorutil.cpp fileerror.cpp fileheader.cpp fsservices.cpp \ growheap.cpp hashtable.cpp haval.cpp msystem.cpp ntmbs.cpp \ refcountobj.cpp serializable.cpp serializer.cpp \ serializerimpl.cpp serializerutil.cpp serstring.cpp \ srefcountobj.cpp srefcounttbl.cpp stdcore.cpp stringutil.cpp \ - timebomb.cpp timeconvert.cpp tw_signal.cpp twlimits.cpp twlocale.cpp \ + timeconvert.cpp tw_signal.cpp twlimits.cpp twlocale.cpp \ unixexcept.cpp usernotify.cpp usernotifystdout.cpp \ wchar16.cpp libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \ core.h coreerrors.h corestrings.h crc32.h debug.h displayencoder.h \ - displayutil.h error.h errorbucket.h errorbucketimpl.h errorgeneral.h \ + displayutil.h epoch.h error.h errorbucket.h errorbucketimpl.h errorgeneral.h \ errortable.h errorutil.h file.h fileerror.h fileheader.h fixedfilebuf.h \ fsservices.h growheap.h hashtable.h haval.h md5.h msystem.h ntdbs.h \ - ntmbs.h package.h platform.h refcountobj.h resources.h \ + ntmbs.h package.h platform.h refcountobj.h resources.h \ serializable.h serializer.h serializerimpl.h serializerutil.h serstring.h \ sha.h srefcountobj.h srefcounttbl.h stdcore.h stringutil.h tasktimer.h \ - tchar.h timebomb.h timeconvert.h tw_signal.h twlimits.h twlocale.h \ + tchar.h timeconvert.h tw_signal.h twlimits.h twlocale.h \ twstringslang.h typed.h types.h unixexcept.h unixfsservices.h upperbound.h \ usernotify.h usernotifystdout.h wchar16.h diff --git a/src/core/timebomb.cpp b/src/core/epoch.cpp similarity index 74% rename from src/core/timebomb.cpp rename to src/core/epoch.cpp index cfe0378..0c0e5ad 100644 --- a/src/core/timebomb.cpp +++ b/src/core/epoch.cpp @@ -30,44 +30,21 @@ // info@tripwire.org or www.tripwire.org. // /////////////////////////////////////////////////////////////////////////////// -// timebomb.h +// epoch.h #include "stdcore.h" -#include "timebomb.h" +#include "epoch.h" #include #include #include "timeconvert.h" #include "corestrings.h" /////////////////////////////////////////////////////////////////////////////// -// TimeBombExploded() -- Call from main(). Prints out timebomb message and -// returns true if main() should exit. -// -bool TimeBombExploded() +bool CheckEpoch() { +#if SIZEOF_TIME_T == 4 + struct tm time_struct; - /* - memset(&time_struct, 0, sizeof(time_struct)); - time_struct.tm_mday = 25; - time_struct.tm_mon = 0; - time_struct.tm_year = 99; - int64 begin = cTimeUtil::DateToTime( &time_struct ); - - memset(&time_struct, 0, sizeof(time_struct)); - time_struct.tm_mday = 1; - time_struct.tm_mon = 4; - time_struct.tm_year = 99; - int64 end = cTimeUtil::DateToTime( &time_struct ); - - int64 now = time(0); - - if (now < begin || now > end) - { - std::cerr << "This beta version of Tripwire(R) has expired.\n"; - return true; - } - */ - // Many functions will fail as we approach the end of the epoch // Rather than crashing, we will exit with a nice message memset(&time_struct, 0, sizeof(time_struct)); @@ -83,5 +60,8 @@ bool TimeBombExploded() } return false; +#else + return false; +#endif } diff --git a/src/core/timebomb.h b/src/core/epoch.h similarity index 91% rename from src/core/timebomb.h rename to src/core/epoch.h index 71ee3a1..53cfd6d 100644 --- a/src/core/timebomb.h +++ b/src/core/epoch.h @@ -30,16 +30,16 @@ // info@tripwire.org or www.tripwire.org. // /////////////////////////////////////////////////////////////////////////////// -// timebomb.h +// epoch.h -#ifndef __TIMEBOMB_H -#define __TIMEBOMB_H +#ifndef __EPOCH_H +#define __EPOCH_H /////////////////////////////////////////////////////////////////////////////// -// TimeBombExploded() -- Call from main(). Prints out timebomb message and +// CheckEpoch() -- Call from main(). Prints out timebomb message and // returns true if main() should exit. // -bool TimeBombExploded(); +bool CheckEpoch(); #endif diff --git a/src/siggen/siggenmain.cpp b/src/siggen/siggenmain.cpp index c975a89..94ca8a4 100644 --- a/src/siggen/siggenmain.cpp +++ b/src/siggen/siggenmain.cpp @@ -43,7 +43,7 @@ #include "core/cmdlineparser.h" #include "core/errorbucketimpl.h" #include "core/usernotifystdout.h" -#include "core/timebomb.h" +#include "core/epoch.h" #include "fs/fsstrings.h" #include "tw/twstrings.h" #include "tw/twutil.h" // for cTWUtil::PrintErrorMsg @@ -104,7 +104,7 @@ int __cdecl _tmain(int argc, const TCHAR** argv) { int ret = 0; - if (TimeBombExploded()) + if (CheckEpoch()) return 1; try diff --git a/src/tripwire/tripwiremain.cpp b/src/tripwire/tripwiremain.cpp index 25d8678..b9d68ba 100644 --- a/src/tripwire/tripwiremain.cpp +++ b/src/tripwire/tripwiremain.cpp @@ -43,7 +43,7 @@ #include "tw/configfile.h" #include "core/errorbucketimpl.h" #include "core/usernotifystdout.h" -#include "core/timebomb.h" +#include "core/epoch.h" #include // for auto_ptr / unique_ptr #include #include @@ -107,7 +107,7 @@ void tw_unexpected_handler() int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) { - if (TimeBombExploded()) + if (CheckEpoch()) return 8; int ret = 0; diff --git a/src/twadmin/twadminmain.cpp b/src/twadmin/twadminmain.cpp index b8f18a0..7ee97c7 100644 --- a/src/twadmin/twadminmain.cpp +++ b/src/twadmin/twadminmain.cpp @@ -42,7 +42,7 @@ #include "tw/twutil.h" #include "tw/twstrings.h" #include "twadminstrings.h" -#include "core/timebomb.h" +#include "core/epoch.h" #include "core/errorbucketimpl.h" #include "core/archive.h" @@ -73,7 +73,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) int ret = 0; - if (TimeBombExploded()) + if (CheckEpoch()) return 1; cTWInit twInit; diff --git a/src/twprint/twprintmain.cpp b/src/twprint/twprintmain.cpp index 4b4531c..e7ffa4a 100644 --- a/src/twprint/twprintmain.cpp +++ b/src/twprint/twprintmain.cpp @@ -42,7 +42,7 @@ #include "core/cmdlineparser.h" #include "core/errorbucketimpl.h" #include "core/usernotifystdout.h" -#include "core/timebomb.h" +#include "core/epoch.h" #include "core/debug.h" @@ -81,7 +81,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ] ) int ret = 0; - if (TimeBombExploded()) + if (CheckEpoch()) return 1; cTWInit twInit;