diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2022-12-22 11:42:14 +0100 |
---|---|---|
committer | Hugo Landau <hlandau@openssl.org> | 2023-01-24 12:33:04 +0000 |
commit | 4700b80d7c6d8adb8d1df100c6d43733d5e8e3d4 (patch) | |
tree | fb9946dde821d708f717c83226fa8775d4c3cf46 | |
parent | 2c83dedef6adb505732f8338e627269a52a920e6 (diff) |
set_trace_data(): prevent double free on OPENSSL_strdup() failure
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19959)
(cherry picked from commit 0fec2121c0c40d8b098896c9bdf629a48fbafa63)
-rw-r--r-- | crypto/trace.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/crypto/trace.c b/crypto/trace.c index 74dbd525a5..3bf9ff62f7 100644 --- a/crypto/trace.c +++ b/crypto/trace.c @@ -288,11 +288,6 @@ static int set_trace_data(int category, int type, BIO **channel, } /* Before running callbacks are done, set new data where appropriate */ - if (channel != NULL && *channel != NULL) { - trace_channels[category].type = type; - trace_channels[category].bio = *channel; - } - if (prefix != NULL && *prefix != NULL) { if ((curr_prefix = OPENSSL_strdup(*prefix)) == NULL) return 0; @@ -305,6 +300,15 @@ static int set_trace_data(int category, int type, BIO **channel, trace_channels[category].suffix = curr_suffix; } + if (channel != NULL && *channel != NULL) { + trace_channels[category].type = type; + trace_channels[category].bio = *channel; + /* + * This must not be done before setting prefix/suffix, + * as those may fail, and then the caller is mislead to free *channel. + */ + } + /* Finally, run the attach callback on the new data */ if (channel != NULL && *channel != NULL) { attach_cb(category, CHANNEL, *channel); |