[前][次][番号順一覧][スレッド一覧]

ruby-changes:39379

From: tenderlove <ko1@a...>
Date: Sat, 1 Aug 2015 04:09:01 +0900 (JST)
Subject: [ruby-changes:39379] tenderlove:r51460 (trunk): * ext/openssl/ossl_ssl.c (ossl_call_tmp_dh_callback): change callback

tenderlove	2015-08-01 04:08:40 +0900 (Sat, 01 Aug 2015)

  New Revision: 51460

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51460

  Log:
    * 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

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/ossl_ssl.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51459)
+++ ChangeLog	(revision 51460)
@@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Aug  1 04:06:29 2015  Aaron Patterson <tenderlove@r...>
+
+	* 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 <tenderlove@r...>
 
 	* ext/openssl/ossl_ssl.c (ossl_call_tmp_dh_callback): Similarly to the
Index: ext/openssl/ossl_ssl.c
===================================================================
--- ext/openssl/ossl_ssl.c	(revision 51459)
+++ ext/openssl/ossl_ssl.c	(revision 51460)
@@ -72,8 +72,6 @@ static VALUE eSSLErrorWaitWritable; https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L72
 #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) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L258
     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) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L293
     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
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]