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

ruby-changes:28335

From: nagachika <ko1@a...>
Date: Sat, 20 Apr 2013 02:16:47 +0900 (JST)
Subject: [ruby-changes:28335] nagachika:r40387 (ruby_2_0_0): merge revision(s) 40304: [Backport #8240]

nagachika	2013-04-20 02:16:37 +0900 (Sat, 20 Apr 2013)

  New Revision: 40387

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

  Log:
    merge revision(s) 40304: [Backport #8240]
    
    * 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 directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/ext/openssl/ossl_ssl.c
    branches/ruby_2_0_0/test/openssl/test_ssl.rb
    branches/ruby_2_0_0/version.h

Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 40386)
+++ ruby_2_0_0/ChangeLog	(revision 40387)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Sat Apr 20 02:09:46 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!
+
 Sat Apr 20 01:56:32 2013  Yuki Yugui Sonoda  <yugui@g...>
 
 	* thread_pthread.c (ruby_init_stack): Avoid using uninitialized value.
Index: ruby_2_0_0/ext/openssl/ossl_ssl.c
===================================================================
--- ruby_2_0_0/ext/openssl/ossl_ssl.c	(revision 40386)
+++ ruby_2_0_0/ext/openssl/ossl_ssl.c	(revision 40387)
@@ -1116,7 +1116,6 @@ ossl_ssl_shutdown(SSL *ssl) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/openssl/ossl_ssl.c#L1116
 static void
 ossl_ssl_free(SSL *ssl)
 {
-    ossl_ssl_shutdown(ssl);
     SSL_free(ssl);
 }
 
@@ -1537,9 +1536,16 @@ ossl_ssl_close(VALUE self) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/openssl/ossl_ssl.c#L1536
 
     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: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 40386)
+++ ruby_2_0_0/version.h	(revision 40387)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2013-04-20"
-#define RUBY_PATCHLEVEL 152
+#define RUBY_PATCHLEVEL 153
 
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 4
Index: ruby_2_0_0/test/openssl/test_ssl.rb
===================================================================
--- ruby_2_0_0/test/openssl/test_ssl.rb	(revision 40386)
+++ ruby_2_0_0/test/openssl/test_ssl.rb	(revision 40387)
@@ -592,6 +592,33 @@ if OpenSSL::OPENSSL_VERSION_NUMBER > 0x1 https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/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)

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r40304


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

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