summaryrefslogtreecommitdiffstats
path: root/crypto/trace.c
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2019-08-10 16:51:12 +0200
committerPaul Yang <kaishen.yy@antfin.com>2019-08-20 11:16:41 +0800
commitcf0932cdd94f067ed18ce78bea038d919f69038f (patch)
treef6bc014904f5dc9e4b90d973b3c213dc1df85638 /crypto/trace.c
parentc85d5e025797f4e77c2166150bbf8745e9d00696 (diff)
prevent endless recursion when trace API is used within OPENSSL_init_crypto()
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Yang <kaishen.yy@antfin.com> (Merged from https://github.com/openssl/openssl/pull/9567)
Diffstat (limited to 'crypto/trace.c')
-rwxr-xr-x[-rw-r--r--]crypto/trace.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/crypto/trace.c b/crypto/trace.c
index d9524da1a6..cc99fff37c 100644..100755
--- a/crypto/trace.c
+++ b/crypto/trace.c
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <string.h>
+#include "internal/thread_once.h"
#include <openssl/bio.h>
#include <openssl/crypto.h>
#include <openssl/trace.h>
@@ -218,6 +219,13 @@ static int trace_detach_cb(int category, int type, const void *data)
return 1;
}
+static int do_ossl_trace_init(void);
+static CRYPTO_ONCE trace_inited = CRYPTO_ONCE_STATIC_INIT;
+DEFINE_RUN_ONCE_STATIC(ossl_trace_init)
+{
+ return do_ossl_trace_init();
+}
+
static int set_trace_data(int category, int type, BIO **channel,
const char **prefix, const char **suffix,
int (*attach_cb)(int, int, const void *),
@@ -227,8 +235,9 @@ static int set_trace_data(int category, int type, BIO **channel,
char *curr_prefix = NULL;
char *curr_suffix = NULL;
- /* Ensure ossl_trace_init() is called */
- OPENSSL_init_crypto(0, NULL);
+ /* Ensure do_ossl_trace_init() is called once */
+ if (!RUN_ONCE(&trace_inited, ossl_trace_init))
+ return 0;
curr_channel = trace_channels[category].bio;
curr_prefix = trace_channels[category].prefix;
@@ -297,19 +306,15 @@ static int set_trace_data(int category, int type, BIO **channel,
return 1;
}
-#endif
-int ossl_trace_init(void)
+static int do_ossl_trace_init(void)
{
-#ifndef OPENSSL_NO_TRACE
trace_lock = CRYPTO_THREAD_lock_new();
- if (trace_lock == NULL)
- return 0;
-#endif
-
- return 1;
+ return trace_lock != NULL;
}
+#endif
+
void ossl_trace_cleanup(void)
{
#ifndef OPENSSL_NO_TRACE