]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
apps/cmp.c: Free bio on error to avoid memory leak
authorJiashengJiang <jiasheng@purdue.edu>
Fri, 16 May 2025 22:34:03 +0000 (18:34 -0400)
committerTomas Mraz <tomas@openssl.org>
Tue, 27 May 2025 17:52:16 +0000 (19:52 +0200)
Call BIO_free() to release bio if ASN1_i2d_bio_of() fails, preventing a memory leak.

Fixes: 6a3579e190 ("CMP: add support for requesting cert template using genm/genp")
Signed-off-by: JiashengJiang <jiasheng@purdue.edu>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27647)

(cherry picked from commit e0ae801728776b53e2be0972846072ce32bea304)

apps/cmp.c

index 5f86ee19a269e2440c2cd251221f326a7a6333db..2b4340d9fb45a89a87295f17afb61f82140be9ee 100644 (file)
@@ -2506,6 +2506,7 @@ static int save_template(const char *file, const OSSL_CRMF_CERTTEMPLATE *tmpl)
                          bio, tmpl)) {
         CMP_err1("error saving certTemplate from genp: cannot write file %s",
                  file);
+        BIO_free(bio);
         return 0;
     } else {
         CMP_info1("stored certTemplate from genp to file '%s'", file);
@@ -2525,6 +2526,7 @@ static int save_keyspec(const char *file, const OSSL_CMP_ATAVS *keyspec)
 
     if (!ASN1_i2d_bio_of(OSSL_CMP_ATAVS, i2d_OSSL_CMP_ATAVS, bio, keyspec)) {
         CMP_err1("error saving keySpec from genp: cannot write file %s", file);
+        BIO_free(bio);
         return 0;
     } else {
         CMP_info1("stored keySpec from genp to file '%s'", file);