Avoid a race condition in loading config settings
authorMatt Caswell <matt@openssl.org>
Tue, 9 Feb 2016 10:55:21 +0000 (10:55 +0000)
committerMatt Caswell <matt@openssl.org>
Tue, 9 Feb 2016 15:11:38 +0000 (15:11 +0000)
A race condition can occur when sending config settings to
OPENSSL_INIT_crypto_library_start()

Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/init.c

index bce8438b9561d9b02515009e6223eb613606c001..1bfde6973ceb41c114296ea50f2188f03fc336dd 100644 (file)
@@ -679,13 +679,17 @@ void OPENSSL_INIT_crypto_library_start(uint64_t opts,
     }
 
     if (opts & OPENSSL_INIT_LOAD_CONFIG) {
+        CRYPTO_w_lock(CRYPTO_LOCK_INIT);
         if (settings != NULL) {
             const OPENSSL_INIT_SETTINGS *curr;
             curr = ossl_init_get_setting(settings,
                                          OPENSSL_INIT_SET_CONF_FILENAME);
-            config_filename = curr == NULL ? NULL : curr->value.type_string;
+            config_filename = (curr == NULL) ? NULL : curr->value.type_string;
+        } else {
+            config_filename = NULL;
         }
         ossl_init_once_run(&config, ossl_init_config);
+        CRYPTO_w_unlock(CRYPTO_LOCK_INIT);
     }
 
     if (opts & OPENSSL_INIT_ASYNC) {