diff options
author | Zachary Scott <e@zzak.io> | 2015-04-13 15:11:27 -0700 |
---|---|---|
committer | Zachary Scott <e@zzak.io> | 2015-04-13 15:11:27 -0700 |
commit | b9ea8ef6048babb301095a2b62897b4bd5b88157 (patch) | |
tree | f38d25b4f43c5fe4b0f65b746c87d97c70261435 /ext | |
parent | f7e556d96ebaa39c9361cbfd56e6eb5bb3b73b7c (diff) | |
download | ruby-openssl-b9ea8ef6048babb301095a2b62897b4bd5b88157.tar.gz |
Apply patch @viktorium to dispose of context after signing
[Bug-#10735](https://bugs.ruby-lang.org/issues/10735)
Diffstat (limited to 'ext')
-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 f781677c..cce6a14f 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); |