From d04efb30a013c3c9061f62081fc6fc020bbbd7b0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 18 Oct 2006 22:33:20 +0000 Subject: r19403: try to fix the crashes in the buildfarm related to timegm (This used to be commit c4e1d2c5ae11acac7dd2cedca411b9b6be84962f) --- source4/lib/replace/timegm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/replace/timegm.c b/source4/lib/replace/timegm.c index ff90626d44..608882d0ce 100644 --- a/source4/lib/replace/timegm.c +++ b/source4/lib/replace/timegm.c @@ -44,13 +44,22 @@ static int is_leap(unsigned y) return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0); } -time_t timegm(struct tm *tm) +time_t rep_timegm(struct tm *tm) { static const unsigned ndays[2][12] ={ {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}}; time_t res = 0; unsigned i; + + if (tm->tm_mon > 12 || + tm->tm_mday > 31 || + tm->tm_min > 60 || + tm->tm_sec > 60 || + tm->tm_hour > 24) { + /* invalid tm structure */ + return 0; + } for (i = 70; i < tm->tm_year; ++i) res += is_leap(i) ? 366 : 365; -- cgit