summaryrefslogtreecommitdiffstats
path: root/crypto/encode_decode
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2021-10-11 15:04:46 +0200
committerTomas Mraz <tomas@openssl.org>2021-10-12 16:45:21 +0200
commit374d5cf2f6b8bdf87c04b5e293a7d291f2c23203 (patch)
tree0df544aa7df6637bda0e7f4ce08b677449438173 /crypto/encode_decode
parent922422119df1f6aabd2a15e6e4108d98b6143adf (diff)
cmp_vfy.c, encoder_lib.c: Fix potential leak of a BIO
Fixes #16787 Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de> (Merged from https://github.com/openssl/openssl/pull/16804)
Diffstat (limited to 'crypto/encode_decode')
-rw-r--r--crypto/encode_decode/encoder_lib.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/crypto/encode_decode/encoder_lib.c b/crypto/encode_decode/encoder_lib.c
index 6c20fbb3d1..cfd9275172 100644
--- a/crypto/encode_decode/encoder_lib.c
+++ b/crypto/encode_decode/encoder_lib.c
@@ -92,7 +92,7 @@ int OSSL_ENCODER_to_fp(OSSL_ENCODER_CTX *ctx, FILE *fp)
int OSSL_ENCODER_to_data(OSSL_ENCODER_CTX *ctx, unsigned char **pdata,
size_t *pdata_len)
{
- BIO *out = BIO_new(BIO_s_mem());
+ BIO *out;
BUF_MEM *buf = NULL;
int ret = 0;
@@ -101,7 +101,10 @@ int OSSL_ENCODER_to_data(OSSL_ENCODER_CTX *ctx, unsigned char **pdata,
return 0;
}
- if (OSSL_ENCODER_to_bio(ctx, out)
+ out = BIO_new(BIO_s_mem());
+
+ if (out != NULL
+ && OSSL_ENCODER_to_bio(ctx, out)
&& BIO_get_mem_ptr(out, &buf) > 0) {
ret = 1; /* Hope for the best. A too small buffer will clear this */