From 66714796c352d5b4cb2f319ed33b13e0141b93e4 Mon Sep 17 00:00:00 2001 From: "Dr. David von Oheimb" Date: Wed, 9 Oct 2024 22:05:19 +0200 Subject: [PATCH] TRACE: automatically respect disabled categories by fixing OSSL_trace_begin() to return NULL when given category is not enabled --- crypto/trace.c | 2 +- doc/man3/OSSL_trace_enabled.pod | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crypto/trace.c b/crypto/trace.c index 51387641de948..3e10d91fc2638 100644 --- a/crypto/trace.c +++ b/crypto/trace.c @@ -475,7 +475,7 @@ BIO *OSSL_trace_begin(int category) char *prefix = NULL; category = ossl_trace_get_category(category); - if (category < 0) + if (category < 0 || !OSSL_trace_enabled(category)) return NULL; channel = trace_channels[category].bio; diff --git a/doc/man3/OSSL_trace_enabled.pod b/doc/man3/OSSL_trace_enabled.pod index da78eba234bcb..987dd7f91af21 100644 --- a/doc/man3/OSSL_trace_enabled.pod +++ b/doc/man3/OSSL_trace_enabled.pod @@ -97,9 +97,10 @@ I is enabled, i.e., if the tracing facility has been statically enabled (see L below) and a trace channel has been registered using L or L. -OSSL_trace_begin() is used to starts a tracing section, and get the -channel for the given I in form of a BIO. +OSSL_trace_begin() is used to start a tracing section, +and get the channel for the given I in form of a BIO. This BIO can only be used for output. +The pointer returned is NULL if the category is invalid or not enabled. OSSL_trace_end() is used to end a tracing section. @@ -211,6 +212,9 @@ expands to =head1 NOTES +It is not needed to guard trace output function calls like +I by I. + If producing the trace output requires carrying out auxiliary calculations, this auxiliary code should be placed inside a conditional block which is executed only if the trace category is enabled.