From 9fefa6063797f94704c09663db13cea9e390eaba Mon Sep 17 00:00:00 2001 From: tenderlove Date: Fri, 31 Jul 2015 19:08:40 +0000 Subject: [PATCH] * ext/openssl/ossl_ssl.c (ossl_call_tmp_dh_callback): change callback to return the Ruby dh (or ecdh) object that the caller cares about instead of doing rb_iv_get / set to communicate. This means we can remove an rb_iv_get call, and only use the set calls for their intended purpose (to prevent the object from being GC'd). * ext/openssl/ossl_ssl.c (ossl_tmp_dh_callback): ditto * ext/openssl/ossl_ssl.c (ossl_call_tmp_ecdh_callback): ditto * ext/openssl/ossl_ssl.c (ossl_tmp_ecdh_callback): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 12 ++++++++++++ ext/openssl/ossl_ssl.c | 26 ++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index b689e23d9d..a50bd8e1ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Sat Aug 1 04:06:29 2015 Aaron Patterson + + * ext/openssl/ossl_ssl.c (ossl_call_tmp_dh_callback): change callback + to return the Ruby dh (or ecdh) object that the caller cares about + instead of doing rb_iv_get / set to communicate. This means we can + remove an rb_iv_get call, and only use the set calls for their + intended purpose (to prevent the object from being GC'd). + + * ext/openssl/ossl_ssl.c (ossl_tmp_dh_callback): ditto + * ext/openssl/ossl_ssl.c (ossl_call_tmp_ecdh_callback): ditto + * ext/openssl/ossl_ssl.c (ossl_tmp_ecdh_callback): ditto + Sat Aug 1 03:49:31 2015 Aaron Patterson * ext/openssl/ossl_ssl.c (ossl_call_tmp_dh_callback): Similarly to the diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index a27f8ecbab..74067f7498 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -72,8 +72,6 @@ static VALUE eSSLErrorWaitWritable; #define ossl_ssl_get_sync_close(o) rb_iv_get((o),"@sync_close") #define ossl_ssl_get_x509(o) rb_iv_get((o),"@x509") #define ossl_ssl_get_key(o) rb_iv_get((o),"@key") -#define ossl_ssl_get_tmp_dh(o) rb_iv_get((o),"@tmp_dh") -#define ossl_ssl_get_tmp_ecdh(o) rb_iv_get((o),"@tmp_ecdh") #define ossl_ssl_set_io(o,v) rb_iv_set((o),"@io",(v)) #define ossl_ssl_set_ctx(o,v) rb_iv_set((o),"@context",(v)) @@ -260,24 +258,24 @@ ossl_call_tmp_dh_callback(VALUE args) dh = rb_apply(cb, rb_intern("call"), args); pkey = GetPKeyPtr(dh); if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DH) return Qfalse; - ossl_ssl_set_tmp_dh(rb_ary_entry(args, 0), dh); - return Qtrue; + return dh; } static DH* ossl_tmp_dh_callback(SSL *ssl, int is_export, int keylength) { - VALUE args, success, rb_ssl; + VALUE args, dh, rb_ssl; rb_ssl = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx); args = rb_ary_new_from_args(3, rb_ssl, INT2FIX(is_export), INT2FIX(keylength)); - success = rb_protect(ossl_call_tmp_dh_callback, args, NULL); - if (!RTEST(success)) return NULL; + dh = rb_protect(ossl_call_tmp_dh_callback, args, NULL); + if (!RTEST(dh)) return NULL; + ossl_ssl_set_tmp_dh(rb_ssl, dh); - return GetPKeyPtr(ossl_ssl_get_tmp_dh(rb_ssl))->pkey.dh; + return GetPKeyPtr(dh)->pkey.dh; } #endif /* OPENSSL_NO_DH */ @@ -295,24 +293,24 @@ ossl_call_tmp_ecdh_callback(VALUE args) ecdh = rb_apply(cb, rb_intern("call"), args); pkey = GetPKeyPtr(ecdh); if (EVP_PKEY_type(pkey->type) != EVP_PKEY_EC) return Qfalse; - ossl_ssl_set_tmp_ecdh(rb_ary_entry(args, 0), ecdh); - return Qtrue; + return ecdh; } static EC_KEY* ossl_tmp_ecdh_callback(SSL *ssl, int is_export, int keylength) { - VALUE args, success, rb_ssl; + VALUE args, ecdh, rb_ssl; rb_ssl = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx); args = rb_ary_new_from_args(3, rb_ssl, INT2FIX(is_export), INT2FIX(keylength)); - success = rb_protect(ossl_call_tmp_ecdh_callback, args, NULL); - if (!RTEST(success)) return NULL; + ecdh = rb_protect(ossl_call_tmp_ecdh_callback, args, NULL); + if (!RTEST(ecdh)) return NULL; + ossl_ssl_set_tmp_ecdh(rb_ssl, ecdh); - return GetPKeyPtr(ossl_ssl_get_tmp_ecdh(rb_ssl))->pkey.ec; + return GetPKeyPtr(ecdh)->pkey.ec; } #endif