From 869b69bed49c74b6bb24b84e9582b121ae123d1d Mon Sep 17 00:00:00 2001 From: dimitr Date: Sun, 21 Mar 2004 09:47:39 +0000 Subject: [PATCH] Fixed server crash when too big/small system year is set up. --- src/jrd/cvt.cpp | 47 ++++++++++++++++++++++++++++++++--------------- src/jrd/evl.cpp | 18 +++++++++++++----- src/jrd/mov.cpp | 10 +++++++--- 3 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/jrd/cvt.cpp b/src/jrd/cvt.cpp index f010962f19..68039c2dc7 100644 --- a/src/jrd/cvt.cpp +++ b/src/jrd/cvt.cpp @@ -1387,18 +1387,27 @@ void CVT_move(const dsc* from, dsc* to, FPTR_ERROR err) tdbb->tdbb_request) { if (tdbb->tdbb_request->req_timestamp) + { clock = tdbb->tdbb_request->req_timestamp; - else { - /* All requests should have a timestamp */ - fb_assert(FALSE); - clock = time(0); + } + else + { + // all requests should have a timestamp + fb_assert(false); + clock = time(NULL); } } else - clock = time(0); - const tm times = *localtime(&clock); + { + clock = time(NULL); + } + const tm* times = localtime(&clock); + if (!times) + { + (*err)(isc_date_range_exceeded, 0); + } GDS_TIMESTAMP enc_times; - isc_encode_timestamp(×, &enc_times); + isc_encode_timestamp(times, &enc_times); ((GDS_TIMESTAMP*) (to->dsc_address))->timestamp_date = enc_times.timestamp_date; } @@ -2419,8 +2428,7 @@ static void string_to_datetime( USHORT position_day = 2; bool have_english_month = false; bool dot_separator_seen = false; - time_t clock; - tm times, times2; + tm times, times2, *ptimes; TEXT buffer[100]; /* arbitrarily large */ const char* string; @@ -2508,8 +2516,13 @@ static void string_to_datetime( /* fetch the current time */ - clock = time(0); - times2 = *localtime(&clock); + const time_t clock = time(NULL); + ptimes = localtime(&clock); + if (!ptimes) + { + (err)(isc_date_range_exceeded, 0); + } + times2 = *ptimes; if (strcmp(temp, NOW) == 0) { isc_encode_timestamp(×2, date); @@ -2639,19 +2652,23 @@ static void string_to_datetime( times.tm_mon = components[position_month]; times.tm_mday = components[position_day]; + const time_t clock = time(NULL); + ptimes = localtime(&clock); + if (!ptimes) + { + (err)(isc_date_range_exceeded, 0); + } + times2 = *ptimes; + /* Handle defaulting of year */ if (description[position_year] == 0) { - clock = time(0); - times2 = *localtime(&clock); times.tm_year = times2.tm_year + 1900; } /* Handle conversion of 2-digit years */ else if (description[position_year] <= 2) { - clock = time(0); - times2 = *localtime(&clock); if (times.tm_year < (times2.tm_year - 50) % 100) times.tm_year += 2000; else diff --git a/src/jrd/evl.cpp b/src/jrd/evl.cpp index df078cb59f..fb01318140 100644 --- a/src/jrd/evl.cpp +++ b/src/jrd/evl.cpp @@ -19,7 +19,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: evl.cpp,v 1.70 2004-03-20 14:57:29 alexpeshkoff Exp $ + * $Id: evl.cpp,v 1.71 2004-03-21 09:47:39 dimitr Exp $ */ /* @@ -901,12 +901,20 @@ dsc* EVL_expr(thread_db* tdbb, jrd_nod* node) // fetch the current clock in order to keep running if (request->req_timestamp) + { clock = request->req_timestamp; - else { - fb_assert(FALSE); - clock = time(0); } - tm times = *localtime(&clock); + else + { + fb_assert(false); + clock = time(NULL); + } + const tm* ptimes = localtime(&clock); + if (!ptimes) + { + ERR_post(isc_date_range_exceeded, 0); + } + tm times = *ptimes; memset(&impure->vlu_desc, 0, sizeof(impure->vlu_desc)); impure->vlu_desc.dsc_address = diff --git a/src/jrd/mov.cpp b/src/jrd/mov.cpp index 4ffe6502f6..115ea6b657 100644 --- a/src/jrd/mov.cpp +++ b/src/jrd/mov.cpp @@ -36,7 +36,7 @@ #include "../jrd/err_proto.h" #include "../jrd/gds_proto.h" #include "../jrd/mov_proto.h" - +#include "gen/iberror.h" int MOV_compare(const dsc* arg1, const dsc* arg2) @@ -586,7 +586,11 @@ void MOV_time_stamp(GDS_TIMESTAMP* date) * **************************************/ const time_t clock = time(NULL); - const tm times = *localtime(&clock); - isc_encode_timestamp(×, date); + const tm* times = localtime(&clock); + if (!times) + { + ERR_post(isc_date_range_exceeded, 0); + } + isc_encode_timestamp(times, date); }