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

ruby-changes:28252

From: emboss <ko1@a...>
Date: Mon, 15 Apr 2013 11:04:23 +0900 (JST)
Subject: [ruby-changes:28252] emboss:r40304 (trunk): * ext/openssl/ossl_ssl.c: Correct shutdown behavior w.r.t GC.

emboss	2013-04-15 11:04:07 +0900 (Mon, 15 Apr 2013)

  New Revision: 40304

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

  Log:
    * ext/openssl/ossl_ssl.c: Correct shutdown behavior w.r.t GC.
    
    * test/openssl/test_ssl.rb: Add tests to verify correct behavior.  
    
    [Bug #8240] Patch provided by Shugo Maeda. Thanks!

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/ossl_ssl.c
    trunk/test/openssl/test_ssl.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40303)
+++ ChangeLog	(revision 40304)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Apr 15 12:54:42 2013  Martin Bosslet  <Martin.Bosslet@g...>
+
+	* ext/openssl/ossl_ssl.c: Correct shutdown behavior w.r.t GC.
+
+	* test/openssl/test_ssl.rb: Add tests to verify correct behavior.
+
+	[Bug #8240] Patch provided by Shugo Maeda. Thanks!
+
 Mon Apr 15 10:23:39 2013  NARUSE, Yui  <naruse@r...>
 
 	* ext/coverage/depend: fix id.h place as r40283.
Index: ext/openssl/ossl_ssl.c
===================================================================
--- ext/openssl/ossl_ssl.c	(revision 40303)
+++ ext/openssl/ossl_ssl.c	(revision 40304)
@@ -1119,7 +1119,6 @@ ossl_ssl_shutdown(SSL *ssl) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1119
 static void
 ossl_ssl_free(SSL *ssl)
 {
-    ossl_ssl_shutdown(ssl);
     SSL_free(ssl);
 }
 
@@ -1538,9 +1537,16 @@ ossl_ssl_close(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1537
 
     ossl_ssl_data_get_struct(self, ssl);
 
-    ossl_ssl_shutdown(ssl);
-    if (RTEST(ossl_ssl_get_sync_close(self)))
-	rb_funcall(ossl_ssl_get_io(self), rb_intern("close"), 0);
+    if (ssl) {
+	VALUE io = ossl_ssl_get_io(self);
+	if (!RTEST(rb_funcall(io, rb_intern("closed?"), 0))) {
+	    ossl_ssl_shutdown(ssl);
+	    SSL_free(ssl);
+	    DATA_PTR(self) = NULL;
+	    if (RTEST(ossl_ssl_get_sync_close(self)))
+		rb_funcall(io, rb_intern("close"), 0);
+	}
+    }
 
     return Qnil;
 }
Index: test/openssl/test_ssl.rb
===================================================================
--- test/openssl/test_ssl.rb	(revision 40303)
+++ test/openssl/test_ssl.rb	(revision 40304)
@@ -592,6 +592,33 @@ if OpenSSL::OPENSSL_VERSION_NUMBER > 0x1 https://github.com/ruby/ruby/blob/trunk/test/openssl/test_ssl.rb#L592
 
 end
 
+  def test_invalid_shutdown_by_gc
+    assert_nothing_raised {
+      start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true){|server, port|
+        10.times {
+          sock = TCPSocket.new("127.0.0.1", port)
+          ssl = OpenSSL::SSL::SSLSocket.new(sock)
+          GC.start
+          ssl.connect
+          sock.close
+        }
+      }
+    }
+  end
+
+  def test_close_after_socket_close
+    start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true){|server, port|
+      sock = TCPSocket.new("127.0.0.1", port)
+      ssl = OpenSSL::SSL::SSLSocket.new(sock)
+      ssl.sync_close = true
+      ssl.connect
+      sock.close
+      assert_nothing_raised do
+        ssl.close
+      end
+    }
+  end
+
   private
 
   def start_server_version(version, ctx_proc=nil, server_proc=nil, &blk)

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

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