diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-12-04 21:22:35 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-12-04 21:22:35 +0900 |
commit | 182604c8c35a7ae7bbf097f7d8b8d2eacc817f2c (patch) | |
tree | 8e07edc4dd662b481bb6c548eee7b1f78f5bccdb /ext/openssl/ossl_pkey_ec.c | |
parent | 72126d6c8b88abd69c3565fc3bbbd5ed1e401611 (diff) | |
download | ruby-openssl-182604c8c35a7ae7bbf097f7d8b8d2eacc817f2c.tar.gz |
bn: keep reference to temporary OpenSSL::BN object created by GetBNPtr()
GetBNPtr() accepts both OpenSSL::BN and Ruby integers. In the latter
case, it creates a temporary OpenSSL::BN internally. The OpenSSL::BN
object immediately disappears from the stack and is not protected from
GC.
Fixes: https://github.com/ruby/openssl/issues/87
Diffstat (limited to 'ext/openssl/ossl_pkey_ec.c')
-rw-r--r-- | ext/openssl/ossl_pkey_ec.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/ext/openssl/ossl_pkey_ec.c b/ext/openssl/ossl_pkey_ec.c index 5191c0f4..fc3f034a 100644 --- a/ext/openssl/ossl_pkey_ec.c +++ b/ext/openssl/ossl_pkey_ec.c @@ -1635,7 +1635,7 @@ static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self) * points | self | arg2[0] | arg2[1] | ... */ long i, num; - VALUE tmp_p, tmp_b; + VALUE bns_tmp, tmp_p, tmp_b; const EC_POINT **points; const BIGNUM **bignums; @@ -1645,9 +1645,13 @@ static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self) ossl_raise(rb_eArgError, "bns must be 1 longer than points; see the documentation"); num = RARRAY_LEN(arg1); + bns_tmp = rb_ary_tmp_new(num); bignums = ALLOCV_N(const BIGNUM *, tmp_b, num); - for (i = 0; i < num; i++) - bignums[i] = GetBNPtr(RARRAY_AREF(arg1, i)); + for (i = 0; i < num; i++) { + VALUE item = RARRAY_AREF(arg1, i); + bignums[i] = GetBNPtr(item); + rb_ary_push(bns_tmp, item); + } points = ALLOCV_N(const EC_POINT *, tmp_p, num); points[0] = point_self; /* self */ |