From 2e607b7ff3f14ffefb94f171e6f50c3fd120e0da Mon Sep 17 00:00:00 2001 From: nagachika Date: Fri, 19 Apr 2013 17:16:37 +0000 Subject: 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! git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@40387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ ext/openssl/ossl_ssl.c | 14 ++++++++++---- test/openssl/test_ssl.rb | 27 +++++++++++++++++++++++++++ version.h | 2 +- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa7fe72401..c9ff762435 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sat Apr 20 02:09:46 2013 Martin Bosslet + + * 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 * thread_pthread.c (ruby_init_stack): Avoid using uninitialized value. diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index d5c07d79a9..62a37b6c5b 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -1116,7 +1116,6 @@ ossl_ssl_shutdown(SSL *ssl) static void ossl_ssl_free(SSL *ssl) { - ossl_ssl_shutdown(ssl); SSL_free(ssl); } @@ -1537,9 +1536,16 @@ ossl_ssl_close(VALUE self) 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; } diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb index cb18c1ae51..f3c1aacaf0 100644 --- a/test/openssl/test_ssl.rb +++ b/test/openssl/test_ssl.rb @@ -592,6 +592,33 @@ if OpenSSL::OPENSSL_VERSION_NUMBER > 0x10001000 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) diff --git a/version.h b/version.h index 263259b568..30dbc428fe 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #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 -- cgit v1.2.3