diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-08-03 21:39:13 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-08-16 14:22:08 +0900 |
commit | 9116661305a9372d07493ea56bd901d77859a490 (patch) | |
tree | 28fca4731edbc89edd9999a86863f52fe3149b22 /ext/openssl/ossl_pkey_ec.c | |
parent | dc1efe5cdd47a1a590438ba1eced114e05468834 (diff) | |
download | ruby-openssl-9116661305a9372d07493ea56bd901d77859a490.tar.gz |
pkey: fix memory leak in PKey::EC#export
It leaks when invalid value is passed as the `cipher` or `pass`
argument.
Diffstat (limited to 'ext/openssl/ossl_pkey_ec.c')
-rw-r--r-- | ext/openssl/ossl_pkey_ec.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/ext/openssl/ossl_pkey_ec.c b/ext/openssl/ossl_pkey_ec.c index c3be042a..894e66d6 100644 --- a/ext/openssl/ossl_pkey_ec.c +++ b/ext/openssl/ossl_pkey_ec.c @@ -542,6 +542,7 @@ static VALUE ossl_ec_key_to_string(VALUE self, VALUE ciph, VALUE pass, int forma int i = -1; int private = 0; VALUE str; + const EVP_CIPHER *cipher = NULL; Require_EC_KEY(self, ec); @@ -554,17 +555,17 @@ static VALUE ossl_ec_key_to_string(VALUE self, VALUE ciph, VALUE pass, int forma if (EC_KEY_get0_private_key(ec)) private = 1; + if (!NIL_P(ciph)) { + cipher = GetCipherPtr(ciph); + pass = ossl_pem_passwd_value(pass); + } + if (!(out = BIO_new(BIO_s_mem()))) ossl_raise(eECError, "BIO_new(BIO_s_mem())"); switch(format) { case EXPORT_PEM: if (private) { - const EVP_CIPHER *cipher = NULL; - if (!NIL_P(ciph)) { - cipher = GetCipherPtr(ciph); - pass = ossl_pem_passwd_value(pass); - } i = PEM_write_bio_ECPrivateKey(out, ec, cipher, NULL, 0, ossl_pem_passwd_cb, (void *)pass); } else { i = PEM_write_bio_EC_PUBKEY(out, ec); |