Skip to content

Commit

Permalink
Merge branch 'ky/pkcs7-empty-signed-data-19974-fixup' into maint-3.0
Browse files Browse the repository at this point in the history
* ky/pkcs7-empty-signed-data-19974-fixup:
  pkcs7: fix memory leak in error path of PKCS7.new and .read_smime
  • Loading branch information
rhenium committed Nov 12, 2024
2 parents bd4c0a9 + 172eee4 commit bd3e938
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ext/openssl/ossl_pkcs7.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ ossl_pkcs7_s_read_smime(VALUE klass, VALUE arg)
BIO_free(in);
if (!pkcs7)
ossl_raise(ePKCS7Error, "Could not parse the PKCS7");
if (!pkcs7->d.ptr)
if (!pkcs7->d.ptr) {
PKCS7_free(pkcs7);
ossl_raise(ePKCS7Error, "No content in PKCS7");
}

data = out ? ossl_membio2str(out) : Qnil;
SetPKCS7(ret, pkcs7);
Expand Down Expand Up @@ -350,8 +352,10 @@ ossl_pkcs7_initialize(int argc, VALUE *argv, VALUE self)
BIO_free(in);
if (!p7)
ossl_raise(rb_eArgError, "Could not parse the PKCS7");
if (!p7->d.ptr)
if (!p7->d.ptr) {
PKCS7_free(p7);
ossl_raise(rb_eArgError, "No content in PKCS7");
}

RTYPEDDATA_DATA(self) = p7;
PKCS7_free(p7_orig);
Expand Down

0 comments on commit bd3e938

Please sign in to comment.