mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 03:07:29 +02:00
Merge pull request #5029 from haydenroche5/asn1_time_diff_2038
This commit is contained in:
31
src/ssl.c
31
src/ssl.c
@ -24345,19 +24345,24 @@ int wolfSSL_ASN1_TIME_check(const WOLFSSL_ASN1_TIME* a)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* From curl.
|
* Convert time to Unix time (GMT).
|
||||||
* time2epoch: time stamp to seconds since epoch in GMT time zone. Similar to
|
|
||||||
* mktime but for GMT only.
|
|
||||||
*/
|
*/
|
||||||
static long long time2epoch(int sec, int min, int hour, int mday, int mon,
|
static long long TimeToUnixTime(int sec, int min, int hour, int mday, int mon,
|
||||||
int year)
|
int year)
|
||||||
{
|
{
|
||||||
|
/* Number of cumulative days from the previous months, starting from
|
||||||
|
* beginning of January. */
|
||||||
static const int monthDaysCumulative [12] = {
|
static const int monthDaysCumulative [12] = {
|
||||||
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
|
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
|
||||||
};
|
};
|
||||||
int leapDays = year - (mon <= 1);
|
int leapDays = year;
|
||||||
leapDays = ((leapDays / 4) - (leapDays / 100) + (leapDays / 400) -
|
|
||||||
(1969 / 4) + (1969 / 100) - (1969 / 400));
|
if (mon <= 1) {
|
||||||
|
--leapDays;
|
||||||
|
}
|
||||||
|
leapDays = leapDays / 4 - leapDays / 100 + leapDays / 400 - 1969 / 4 +
|
||||||
|
1969 / 100 - 1969 / 400;
|
||||||
|
|
||||||
return ((((long long) (year - 1970) * 365 + leapDays +
|
return ((((long long) (year - 1970) * 365 + leapDays +
|
||||||
monthDaysCumulative[mon] + mday - 1) * 24 + hour) * 60 + min) * 60 +
|
monthDaysCumulative[mon] + mday - 1) * 24 + hour) * 60 + min) * 60 +
|
||||||
sec;
|
sec;
|
||||||
@ -24413,10 +24418,10 @@ int wolfSSL_ASN1_TIME_diff(int *days, int *secs, const WOLFSSL_ASN1_TIME *from,
|
|||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We use time2epoch here instead of XMKTIME to avoid the Year 2038 problem
|
/* We use TimeToUnixTime here instead of XMKTIME to avoid the Year 2038
|
||||||
* on platforms where time_t is 32 bits. struct tm stores the year as years
|
* Problem on platforms where time_t is 32 bits. struct tm stores the year
|
||||||
* since 1900, so we add 1900 to the year. */
|
* as years since 1900, so we add 1900 to the year. */
|
||||||
fromSecs = time2epoch(fromTmGmt->tm_sec, fromTmGmt->tm_min,
|
fromSecs = TimeToUnixTime(fromTmGmt->tm_sec, fromTmGmt->tm_min,
|
||||||
fromTmGmt->tm_hour, fromTmGmt->tm_mday,
|
fromTmGmt->tm_hour, fromTmGmt->tm_mday,
|
||||||
fromTmGmt->tm_mon, fromTmGmt->tm_year + 1900);
|
fromTmGmt->tm_mon, fromTmGmt->tm_year + 1900);
|
||||||
|
|
||||||
@ -24433,7 +24438,7 @@ int wolfSSL_ASN1_TIME_diff(int *days, int *secs, const WOLFSSL_ASN1_TIME *from,
|
|||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
toSecs = time2epoch(toTmGmt->tm_sec, toTmGmt->tm_min, toTmGmt->tm_hour,
|
toSecs = TimeToUnixTime(toTmGmt->tm_sec, toTmGmt->tm_min, toTmGmt->tm_hour,
|
||||||
toTmGmt->tm_mday, toTmGmt->tm_mon,
|
toTmGmt->tm_mday, toTmGmt->tm_mon,
|
||||||
toTmGmt->tm_year + 1900);
|
toTmGmt->tm_year + 1900);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user