mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-25 13:25:29 +00:00
Add safety check to sample mutex implementation
Due to inconsistent freeing strategy in pkparse.c the sample mutex implementation in threading.c could lead to undefined behaviour by destroying the same mutex several times. This fix prevents mutexes from being destroyed several times in the sample threading implementation.
This commit is contained in:
parent
4ed1c00f10
commit
433d4c84b3
|
@ -15,6 +15,8 @@ Bugfix
|
|||
* Fixed the sample applications gen_key.c, cert_req.c and cert_write.c for
|
||||
builds where the configuration MBEDTLS_PEM_WRITE_C is not defined. Found
|
||||
by inestlerode. #559.
|
||||
* Fixed default threading implementation to avoid accidental double
|
||||
initialisations and double frees.
|
||||
|
||||
= mbed TLS 2.1.5 branch released 2016-06-28
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#if defined(MBEDTLS_THREADING_PTHREAD)
|
||||
static void threading_mutex_init_pthread( mbedtls_threading_mutex_t *mutex )
|
||||
{
|
||||
if( mutex == NULL )
|
||||
if( mutex == NULL || mutex->is_valid )
|
||||
return;
|
||||
|
||||
mutex->is_valid = pthread_mutex_init( &mutex->mutex, NULL ) == 0;
|
||||
|
@ -40,10 +40,11 @@ static void threading_mutex_init_pthread( mbedtls_threading_mutex_t *mutex )
|
|||
|
||||
static void threading_mutex_free_pthread( mbedtls_threading_mutex_t *mutex )
|
||||
{
|
||||
if( mutex == NULL )
|
||||
if( mutex == NULL || !mutex->is_valid )
|
||||
return;
|
||||
|
||||
(void) pthread_mutex_destroy( &mutex->mutex );
|
||||
mutex->is_valid = 0;
|
||||
}
|
||||
|
||||
static int threading_mutex_lock_pthread( mbedtls_threading_mutex_t *mutex )
|
||||
|
|
Loading…
Reference in a new issue