Fix possible race in ssl_list_ciphersuites()

Thread A: executing for loop of ssl_list_ciphersuites()
Thread B: call ssl_list_cipher_suites(), see init == 0
Thread A: return, start using the result
Thread B: memset(0) on the list used by thread A
This commit is contained in:
Manuel Pégourié-Gonnard 2013-09-07 15:04:26 +02:00 committed by Paul Bakker
parent 055ef61658
commit bc4b7f08ba

View file

@ -844,14 +844,12 @@ const int *ssl_list_ciphersuites( void )
size_t i; size_t i;
size_t max = sizeof(supported_ciphersuites) / sizeof(int); size_t max = sizeof(supported_ciphersuites) / sizeof(int);
memset( supported_ciphersuites, 0x00, sizeof(supported_ciphersuites) );
/* Leave room for a final 0 */
for( i = 0; i < max - 1 && p[i] != 0; i++ ) for( i = 0; i < max - 1 && p[i] != 0; i++ )
{ {
if( ssl_ciphersuite_from_id( p[i] ) != NULL ) if( ssl_ciphersuite_from_id( p[i] ) != NULL )
*(q++) = p[i]; *(q++) = p[i];
} }
*q = 0;
supported_init = 1; supported_init = 1;
} }