]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix a memleak in prepare_rsa_params
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 11 Sep 2023 10:34:02 +0000 (12:34 +0200)
committerTomas Mraz <tomas@openssl.org>
Wed, 13 Sep 2023 05:46:46 +0000 (07:46 +0200)
This affects only RSA-PSS keys with params using
negative salt legth, or in case of out of memory.
This fixes a memory leak reported in #22049.

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22061)

providers/implementations/encode_decode/encode_key2any.c

index c1b0dea7803e4204f601d4897aca998028970a94..ae6d7d0a681d306d3e5579ff548e49018bbe4380 100644 (file)
@@ -856,14 +856,17 @@ static int prepare_rsa_params(const void *rsa, int nid, int save,
                 case 1:
                     if ((str = OPENSSL_malloc(str_sz)) == NULL
                         || !WPACKET_init_der(&pkt, str, str_sz)) {
+                        WPACKET_cleanup(&pkt);
                         goto err;
                     }
                     break;
                 }
                 if (!ossl_DER_w_RSASSA_PSS_params(&pkt, -1, pss)
                     || !WPACKET_finish(&pkt)
-                    || !WPACKET_get_total_written(&pkt, &str_sz))
+                    || !WPACKET_get_total_written(&pkt, &str_sz)) {
+                    WPACKET_cleanup(&pkt);
                     goto err;
+                }
                 WPACKET_cleanup(&pkt);
 
                 /*