From c2e4e5d248567d4eea5bf6d525bdbcc09099ba6e Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Tue, 19 Jul 2016 19:42:11 +0200 Subject: Change all our uses of CRYPTO_THREAD_run_once to use RUN_ONCE instead That way, we have a way to check if the init function was successful or not. Reviewed-by: Kurt Roeckx --- ssl/ssl_cert.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'ssl/ssl_cert.c') diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c index 2a07ee6910..c155e787d5 100644 --- a/ssl/ssl_cert.c +++ b/ssl/ssl_cert.c @@ -29,6 +29,7 @@ #include #include #include "ssl_locl.h" +#include "internal/thread_once.h" static int ssl_security_default_callback(const SSL *s, const SSL_CTX *ctx, int op, int bits, int nid, void *other, @@ -37,17 +38,19 @@ static int ssl_security_default_callback(const SSL *s, const SSL_CTX *ctx, int o static CRYPTO_ONCE ssl_x509_store_ctx_once = CRYPTO_ONCE_STATIC_INIT; static volatile int ssl_x509_store_ctx_idx = -1; -static void ssl_x509_store_ctx_init(void) +DEFINE_RUN_ONCE_STATIC(ssl_x509_store_ctx_init) { ssl_x509_store_ctx_idx = X509_STORE_CTX_get_ex_new_index(0, "SSL for verify callback", NULL, NULL, NULL); + return ssl_x509_store_ctx_idx >= 0; } int SSL_get_ex_data_X509_STORE_CTX_idx(void) { - CRYPTO_THREAD_run_once(&ssl_x509_store_ctx_once, ssl_x509_store_ctx_init); + if (!RUN_ONCE(&ssl_x509_store_ctx_once, ssl_x509_store_ctx_init)) + return -1; return ssl_x509_store_ctx_idx; } -- cgit v1.2.3