]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix a leak in ossl_encode_ctx_setup_for_pkey
authorMatt Caswell <matt@openssl.org>
Mon, 21 Aug 2023 11:19:44 +0000 (12:19 +0100)
committerMatt Caswell <matt@openssl.org>
Wed, 23 Aug 2023 15:07:34 +0000 (16:07 +0100)
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)

(cherry picked from commit 8ef63b6ff8301a0139c00df6c40173a63fd2db01)

crypto/encode_decode/encoder_pkey.c

index 58c279f6ebab9c92b878854fd78390a8d0f38d0c..24b16f5a5546bcaa67b4c3593bd8c76a23ca8143 100644 (file)
@@ -286,8 +286,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);