Skip to content

Commit 6930179

Browse files
Fix wolfssl_asn1_time_to_tm setting unexpected fields in tm struct.
1 parent dbb5ee3 commit 6930179

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/ssl_asn1.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3652,6 +3652,9 @@ static int wolfssl_asn1_time_to_tm(const WOLFSSL_ASN1_TIME* asnTime,
36523652
const unsigned char* asn1TimeBuf;
36533653
int asn1TimeBufLen;
36543654
int i = 0;
3655+
#ifdef XMKTIME
3656+
struct tm localTm = {0};
3657+
#endif
36553658

36563659
/* Get the string buffer - fixed array, can't fail. */
36573660
asn1TimeBuf = wolfSSL_ASN1_TIME_get_data(asnTime);
@@ -3706,8 +3709,13 @@ static int wolfssl_asn1_time_to_tm(const WOLFSSL_ASN1_TIME* asnTime,
37063709
tm->tm_sec += (asn1TimeBuf[i] - '0');
37073710

37083711
#ifdef XMKTIME
3709-
/* Call XMKTIME on tm to get tm_wday and tm_yday fields populated. */
3710-
XMKTIME(tm);
3712+
XMEMCPY(&localTm, tm, sizeof(struct tm));
3713+
/* Call XMKTIME on tm to get tm_wday and tm_yday fields populated.
3714+
Note that localTm is used here to avoid modifying other fields,
3715+
such as tm_isdst/tm_gmtoff. */
3716+
XMKTIME(&localTm);
3717+
tm->tm_wday = localTm.tm_wday;
3718+
tm->tm_yday = localTm.tm_yday;
37113719
#endif
37123720
}
37133721

0 commit comments

Comments
 (0)