Fix a leak in ossl_encode_ctx_setup_for_pkey

Make sure we free the stack of names we allocated in an error path.

Found by the reproducible error patch in #21668

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/21796)
This commit is contained in:
Matt Caswell 2023-08-21 12:19:44 +01:00
parent 617cab094f
commit 8ef63b6ff8

View File

@ -284,8 +284,10 @@ static int ossl_encoder_ctx_setup_for_pkey(OSSL_ENCODER_CTX *ctx,
end = sk_OPENSSL_CSTRING_num(encoder_data.names);
if (end > 0) {
encoder_data.id_names = OPENSSL_malloc(end * sizeof(int));
if (encoder_data.id_names == NULL)
if (encoder_data.id_names == NULL) {
sk_OPENSSL_CSTRING_free(keymgmt_data.names);
goto err;
}
for (i = 0; i < end; ++i) {
const char *name = sk_OPENSSL_CSTRING_value(keymgmt_data.names, i);