make more strict

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18607 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2006-10-19 16:19:32 +00:00
parent ffcf477e66
commit 1ae8d3c3b9

View File

@@ -35,8 +35,6 @@
RCSID("$Id$"); RCSID("$Id$");
#ifndef HAVE_TIMEGM
static int static int
is_leap(unsigned y) is_leap(unsigned y)
{ {
@@ -44,6 +42,12 @@ is_leap(unsigned y)
return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0); return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0);
} }
/*
* This is a simplifed version of _der_timegm that doesn't accept out
* of bound values that timegm(3) normally accepts but those are not
* valid in asn1 encodings.
*/
time_t time_t
_der_timegm (struct tm *tm) _der_timegm (struct tm *tm)
{ {
@@ -53,10 +57,18 @@ _der_timegm (struct tm *tm)
time_t res = 0; time_t res = 0;
unsigned i; unsigned i;
/* XXX this is wrong, needs to handle out of range if (tm->tm_year < 0)
* months, days, hours, min, sec */ return -1;
if (tm->tm_mon < 0 || tm->tm_mon > 11) if (tm->tm_mon < 0 || tm->tm_mon > 11)
return -1; return -1;
if (tm->tm_mday < 1 || tm->tm_mday > ndays[is_leap(tm->tm_year)][tm->tm_mon])
return -1;
if (tm->tm_hour < 0 || tm->tm_hour > 23)
return -1;
if (tm->tm_min < 0 || tm->tm_min > 59)
return -1;
if (tm->tm_sec < 0 || tm->tm_sec > 59)
return -1;
for (i = 70; i < tm->tm_year; ++i) for (i = 70; i < tm->tm_year; ++i)
res += is_leap(i) ? 366 : 365; res += is_leap(i) ? 366 : 365;
@@ -72,5 +84,3 @@ _der_timegm (struct tm *tm)
res += tm->tm_sec; res += tm->tm_sec;
return res; return res;
} }
#endif /* HAVE_TIMEGM */