diff options
author | Dr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com> | 2019-03-13 00:14:55 +0100 |
---|---|---|
committer | Dr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com> | 2019-03-15 08:48:43 +0100 |
commit | fe50e115718edb8938443a45c8014d6568537bd0 (patch) | |
tree | a701f87f69ebf9cdc6e15ce45ae6d7f52dfbe371 /apps/openssl.c | |
parent | 13d06925e8cb15bf4247f14280d535618e7a4b2b (diff) | |
download | openssl-new-fe50e115718edb8938443a45c8014d6568537bd0.tar.gz |
trace: ensure correct grouping
It is important that output to the trace channels occurs only inside
a trace group. This precondtion is satisfied whenever the standard
TRACE macros are used. It can be violated only by a bad programming
mistake, like copying the 'trc_out' pointer and using it outside
the trace group.
This commit enforces correct pairing of the OSSL_TRACE_CTRL_BEGIN and
OSSL_TRACE_CTRL_END callbacks, and checks that OSSL_TRACE_CTRL_WRITE
callbacks only occur within such groups.
While implementing it, it turned out that the group assertion failed
apps/openssl.c:152: OpenSSL internal error: \
Assertion failed: trace_data->ingroup
because the set_trace_data() function invokes some callbacks which
generate trace output, but the correct channel type was set only
after the set_trace_data() call.
To fix the failed assertions, the correct channel type is now set
inside the set_trace_data() call, instead of doing it afterwards.
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8463)
Diffstat (limited to 'apps/openssl.c')
-rw-r--r-- | apps/openssl.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/apps/openssl.c b/apps/openssl.c index db1dbb767d..119d3e8ff6 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -136,6 +136,8 @@ static size_t internal_trace_cb(const char *buf, size_t cnt, switch (cmd) { case OSSL_TRACE_CTRL_BEGIN: + if (!ossl_assert(!trace_data->ingroup)) + return 0; trace_data->ingroup = 1; tid.ltid = 0; @@ -147,9 +149,14 @@ static size_t internal_trace_cb(const char *buf, size_t cnt, strlen(buffer), buffer); break; case OSSL_TRACE_CTRL_WRITE: + if (!ossl_assert(trace_data->ingroup)) + return 0; + ret = BIO_write(trace_data->bio, buf, cnt); break; case OSSL_TRACE_CTRL_END: + if (!ossl_assert(trace_data->ingroup)) + return 0; trace_data->ingroup = 0; BIO_ctrl(trace_data->bio, PREFIX_CTRL_SET_PREFIX, 0, NULL); |