mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Use gmtime_r to fix thread-safety issue, and use mbedtls_time on Windows
This commit is contained in:
@ -114,9 +114,6 @@ void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t *
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
mbedtls_mutex_init( &mbedtls_threading_readdir_mutex );
|
||||
#endif
|
||||
#if defined(MBEDTLS_HAVE_TIME_DATE)
|
||||
mbedtls_mutex_init( &mbedtls_threading_gmtime_mutex );
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@ -127,9 +124,6 @@ void mbedtls_threading_free_alt( void )
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
mbedtls_mutex_free( &mbedtls_threading_readdir_mutex );
|
||||
#endif
|
||||
#if defined(MBEDTLS_HAVE_TIME_DATE)
|
||||
mbedtls_mutex_free( &mbedtls_threading_gmtime_mutex );
|
||||
#endif
|
||||
}
|
||||
#endif /* MBEDTLS_THREADING_ALT */
|
||||
|
||||
@ -142,8 +136,5 @@ void mbedtls_threading_free_alt( void )
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex MUTEX_INIT;
|
||||
#endif
|
||||
#if defined(MBEDTLS_HAVE_TIME_DATE)
|
||||
mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex MUTEX_INIT;
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
@ -59,14 +59,10 @@
|
||||
#define mbedtls_snprintf snprintf
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
#include "mbedtls/platform_time.h"
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#if defined(MBEDTLS_HAVE_TIME_DATE)
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
@ -903,36 +899,18 @@ int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name )
|
||||
* Set the time structure to the current time.
|
||||
* Return 0 on success, non-zero on failure.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
|
||||
static int x509_get_current_time( mbedtls_x509_time *now )
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
|
||||
GetSystemTime( &st );
|
||||
|
||||
now->year = st.wYear;
|
||||
now->mon = st.wMonth;
|
||||
now->day = st.wDay;
|
||||
now->hour = st.wHour;
|
||||
now->min = st.wMinute;
|
||||
now->sec = st.wSecond;
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
static int x509_get_current_time( mbedtls_x509_time *now )
|
||||
{
|
||||
struct tm *lt;
|
||||
struct tm *lt, tm_buf;
|
||||
mbedtls_time_t tt;
|
||||
int ret = 0;
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
if( mbedtls_mutex_lock( &mbedtls_threading_gmtime_mutex ) != 0 )
|
||||
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
|
||||
#endif
|
||||
|
||||
tt = mbedtls_time( NULL );
|
||||
lt = gmtime( &tt );
|
||||
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
|
||||
lt = gmtime_s( &tm_buf, &tt ) == 0 ? &tm_buf : NULL;
|
||||
#else
|
||||
lt = gmtime_r( &tt, &tm_buf );
|
||||
#endif
|
||||
|
||||
if( lt == NULL )
|
||||
ret = -1;
|
||||
@ -946,14 +924,8 @@ static int x509_get_current_time( mbedtls_x509_time *now )
|
||||
now->sec = lt->tm_sec;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
if( mbedtls_mutex_unlock( &mbedtls_threading_gmtime_mutex ) != 0 )
|
||||
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
|
||||
#endif
|
||||
|
||||
return( ret );
|
||||
}
|
||||
#endif /* _WIN32 && !EFIX64 && !EFI32 */
|
||||
|
||||
/*
|
||||
* Return 0 if before <= after, 1 otherwise
|
||||
|
Reference in New Issue
Block a user