diff options
author | Zachary Scott <mail@zzak.io> | 2015-11-13 13:59:07 +0900 |
---|---|---|
committer | Zachary Scott <mail@zzak.io> | 2015-11-13 13:59:07 +0900 |
commit | 9dc244d2708f85fd6b815095f7562cc27ece7d7e (patch) | |
tree | 02efd4db14ede813311824e746608d4172038b1d /ext/openssl/ossl_pkey.c | |
parent | bf0bd27d6446a62d2ba8deb27ef19a3c6a291917 (diff) | |
parent | b9ea8ef6048babb301095a2b62897b4bd5b88157 (diff) | |
download | ruby-openssl-9dc244d2708f85fd6b815095f7562cc27ece7d7e.tar.gz |
Merge pull request #31 from ruby/ruby-bug-10735
Apply patch @viktorium to dispose of context after signing
Diffstat (limited to 'ext/openssl/ossl_pkey.c')
-rw-r--r-- | ext/openssl/ossl_pkey.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c index 0b7faf96..4a3d3e59 100644 --- a/ext/openssl/ossl_pkey.c +++ b/ext/openssl/ossl_pkey.c @@ -289,6 +289,7 @@ ossl_pkey_sign(VALUE self, VALUE digest, VALUE data) EVP_MD_CTX ctx; unsigned int buf_len; VALUE str; + int result; if (rb_funcallv(self, id_private_q, 0, NULL) != Qtrue) { ossl_raise(rb_eArgError, "Private key is needed."); @@ -298,7 +299,9 @@ ossl_pkey_sign(VALUE self, VALUE digest, VALUE data) StringValue(data); EVP_SignUpdate(&ctx, RSTRING_PTR(data), RSTRING_LEN(data)); str = rb_str_new(0, EVP_PKEY_size(pkey)+16); - if (!EVP_SignFinal(&ctx, (unsigned char *)RSTRING_PTR(str), &buf_len, pkey)) + result = EVP_SignFinal(&ctx, (unsigned char *)RSTRING_PTR(str), &buf_len, pkey) + EVP_MD_CTX_cleanup(&ctx); + if (!result) ossl_raise(ePKeyError, NULL); assert((long)buf_len <= RSTRING_LEN(str)); rb_str_set_len(str, buf_len); |