mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-25 20:25:53 +01:00
Fix potential NULL dereference.
Introduced when moving from gmtime_r() to gmtime(). Found with fbinfer.
This commit is contained in:
parent
e91e21cf1b
commit
57e10d71be
@ -820,9 +820,13 @@ int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name )
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_HAVE_TIME_DATE)
|
#if defined(MBEDTLS_HAVE_TIME_DATE)
|
||||||
|
/*
|
||||||
|
* 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 )
|
static int x509_get_current_time( mbedtls_x509_time *now )
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
|
|
||||||
SYSTEMTIME st;
|
SYSTEMTIME st;
|
||||||
|
|
||||||
GetSystemTime( &st );
|
GetSystemTime( &st );
|
||||||
@ -833,9 +837,15 @@ static int x509_get_current_time( mbedtls_x509_time *now )
|
|||||||
now->hour = st.wHour;
|
now->hour = st.wHour;
|
||||||
now->min = st.wMinute;
|
now->min = st.wMinute;
|
||||||
now->sec = st.wSecond;
|
now->sec = st.wSecond;
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
|
static int x509_get_current_time( mbedtls_x509_time *now )
|
||||||
|
{
|
||||||
struct tm *lt;
|
struct tm *lt;
|
||||||
time_t tt;
|
time_t tt;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
if( mbedtls_mutex_lock( &mbedtls_threading_gmtime_mutex ) != 0 )
|
if( mbedtls_mutex_lock( &mbedtls_threading_gmtime_mutex ) != 0 )
|
||||||
@ -845,22 +855,26 @@ static int x509_get_current_time( mbedtls_x509_time *now )
|
|||||||
tt = time( NULL );
|
tt = time( NULL );
|
||||||
lt = gmtime( &tt );
|
lt = gmtime( &tt );
|
||||||
|
|
||||||
now->year = lt->tm_year + 1900;
|
if( lt == NULL )
|
||||||
now->mon = lt->tm_mon + 1;
|
ret = -1;
|
||||||
now->day = lt->tm_mday;
|
else
|
||||||
now->hour = lt->tm_hour;
|
{
|
||||||
now->min = lt->tm_min;
|
now->year = lt->tm_year + 1900;
|
||||||
now->sec = lt->tm_sec;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
if( mbedtls_mutex_unlock( &mbedtls_threading_gmtime_mutex ) != 0 )
|
if( mbedtls_mutex_unlock( &mbedtls_threading_gmtime_mutex ) != 0 )
|
||||||
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
|
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _WIN32 && !EFIX64 && !EFI32 */
|
return( ret );
|
||||||
|
|
||||||
return( 0 );
|
|
||||||
}
|
}
|
||||||
|
#endif /* _WIN32 && !EFIX64 && !EFI32 */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return 0 if before <= after, 1 otherwise
|
* Return 0 if before <= after, 1 otherwise
|
||||||
|
Loading…
Reference in New Issue
Block a user