Skip to content

Commit

Permalink
TRACE: automatically respect disabled categories
Browse files Browse the repository at this point in the history
by fixing OSSL_trace_begin() to return NULL when given category is not enabled
  • Loading branch information
DDvO committed Oct 9, 2024
1 parent ee0bf38 commit 6671479
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crypto/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions doc/man3/OSSL_trace_enabled.pod
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ I<category> is enabled, i.e., if the tracing facility has been statically
enabled (see L</Configure Tracing> below) and a trace channel has been
registered using L<OSSL_trace_set_channel(3)> or L<OSSL_trace_set_callback(3)>.

OSSL_trace_begin() is used to starts a tracing section, and get the
channel for the given I<category> in form of a BIO.
OSSL_trace_begin() is used to start a tracing section,
and get the channel for the given I<category> 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.

Expand Down Expand Up @@ -211,6 +212,9 @@ expands to

=head1 NOTES

It is not needed to guard trace output function calls like
I<OSSL_TRACE(category, ...)> by I<OSSL_TRACE_ENABLED(category)>.

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.
Expand Down

0 comments on commit 6671479

Please sign in to comment.