]> 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:01:30 +0000 (16:01 +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)

crypto/encode_decode/encoder_pkey.c

index 6954343422afddcc7ce6e16b4cd457b79dfd2893..d482260102b38daa1af87c4464851c77e03fd451 100644 (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);