diff options
author | tb <> | 2023-03-10 11:55:38 +0000 |
---|---|---|
committer | tb <> | 2023-03-10 11:55:38 +0000 |
commit | ccbb1a9bdc8ccf09bfe96b0d7e030089cd54e33b (patch) | |
tree | 8824c1d526c219d0ad09f979781779024eb52d3e | |
parent | 72196349be7c62460f3c81bbcf4f357d46ba91de (diff) | |
download | openbsd-ccbb1a9bdc8ccf09bfe96b0d7e030089cd54e33b.tar.gz openbsd-ccbb1a9bdc8ccf09bfe96b0d7e030089cd54e33b.tar.bz2 openbsd-ccbb1a9bdc8ccf09bfe96b0d7e030089cd54e33b.zip |
ASN.1 BIO: properly wire up prefix_free and suffix_free
If something goes wrong before the ASN.1 BIO state machine has passed
both flushing states, asn1_bio_free() forgets to free the ndef_aux
and the ex_arg since the prefix_free() and suffix_free callbacks are
not called.
This can lead to leaks, notably in streaming bios.
Part of https://github.com/openssl/openssl/pull/15999
I have a regress covering this but it is not yet ready to land.
ok beck jsing
-rw-r--r-- | src/lib/libcrypto/asn1/bio_asn1.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/lib/libcrypto/asn1/bio_asn1.c b/src/lib/libcrypto/asn1/bio_asn1.c index 05bc1f7ad3..21f33ecfc9 100644 --- a/src/lib/libcrypto/asn1/bio_asn1.c +++ b/src/lib/libcrypto/asn1/bio_asn1.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bio_asn1.c,v 1.18 2023/03/04 11:58:29 tb Exp $ */ | 1 | /* $OpenBSD: bio_asn1.c,v 1.19 2023/03/10 11:55:38 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -177,6 +177,12 @@ asn1_bio_free(BIO *b) | |||
177 | ctx = (BIO_ASN1_BUF_CTX *) b->ptr; | 177 | ctx = (BIO_ASN1_BUF_CTX *) b->ptr; |
178 | if (ctx == NULL) | 178 | if (ctx == NULL) |
179 | return 0; | 179 | return 0; |
180 | |||
181 | if (ctx->prefix_free != NULL) | ||
182 | ctx->prefix_free(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg); | ||
183 | if (ctx->suffix_free != NULL) | ||
184 | ctx->suffix_free(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg); | ||
185 | |||
180 | free(ctx->buf); | 186 | free(ctx->buf); |
181 | free(ctx); | 187 | free(ctx); |
182 | b->init = 0; | 188 | b->init = 0; |