diff --git a/src/ssl_asn1.c b/src/ssl_asn1.c index 5a09e2742..20dbe6758 100644 --- a/src/ssl_asn1.c +++ b/src/ssl_asn1.c @@ -3652,6 +3652,9 @@ static int wolfssl_asn1_time_to_tm(const WOLFSSL_ASN1_TIME* asnTime, const unsigned char* asn1TimeBuf; int asn1TimeBufLen; int i = 0; +#ifdef XMKTIME + struct tm localTm = {0}; +#endif /* Get the string buffer - fixed array, can't fail. */ asn1TimeBuf = wolfSSL_ASN1_TIME_get_data(asnTime); @@ -3706,8 +3709,13 @@ static int wolfssl_asn1_time_to_tm(const WOLFSSL_ASN1_TIME* asnTime, tm->tm_sec += (asn1TimeBuf[i] - '0'); #ifdef XMKTIME - /* Call XMKTIME on tm to get tm_wday and tm_yday fields populated. */ - XMKTIME(tm); + XMEMCPY(&localTm, tm, sizeof(struct tm)); + /* Call XMKTIME on tm to get tm_wday and tm_yday fields populated. + Note that localTm is used here to avoid modifying other fields, + such as tm_isdst/tm_gmtoff. */ + XMKTIME(&localTm); + tm->tm_wday = localTm.tm_wday; + tm->tm_yday = localTm.tm_yday; #endif }