From 5fff23b92abbf303c02f9e35f38a552372b2750a Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Wed, 26 Mar 2014 15:34:54 +0100
Subject: [PATCH] x509_get_current_time() uses localtime_r() to prevent thread
issues
---
ChangeLog | 1 +
library/x509.c | 16 ++++++++--------
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 38f14ddb5..a6aa5b569 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -59,6 +59,7 @@ Bugfix
* ssl_handshake_init() was leaving dirty pointers in subcontexts if malloc
of one of them failed
* Fix typo in rsa_copy() that impacted PKCS#1 v2 contexts
+ * x509_get_current_time() uses localtime_r() to prevent thread issues
= PolarSSL 1.3.4 released on 2014-01-27
Features
diff --git a/library/x509.c b/library/x509.c
index 9c3b0f4aa..57de5450d 100644
--- a/library/x509.c
+++ b/library/x509.c
@@ -636,18 +636,18 @@ static void x509_get_current_time( x509_time *now )
now->min = st.wMinute;
now->sec = st.wSecond;
#else
- struct tm *lt;
+ struct tm lt;
time_t tt;
tt = time( NULL );
- lt = localtime( &tt );
+ localtime_r( &tt, < );
- now->year = lt->tm_year + 1900;
- now->mon = lt->tm_mon + 1;
- now->day = lt->tm_mday;
- now->hour = lt->tm_hour;
- now->min = lt->tm_min;
- now->sec = lt->tm_sec;
+ now->year = lt.tm_year + 1900;
+ now->mon = lt.tm_mon + 1;
+ now->day = lt.tm_mday;
+ now->hour = lt.tm_hour;
+ now->min = lt.tm_min;
+ now->sec = lt.tm_sec;
#endif
}