diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-04-19 17:16:37 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-04-19 17:16:37 +0000 |
commit | 2e607b7ff3f14ffefb94f171e6f50c3fd120e0da (patch) | |
tree | d09613eb74da918b46fe9dd25657db47702cdd9e | |
parent | 6ba7e6cc60842d6aff6229c117c2aa6b0fe2cb9f (diff) |
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
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | ext/openssl/ossl_ssl.c | 14 | ||||
-rw-r--r-- | test/openssl/test_ssl.rb | 27 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 46 insertions, 5 deletions
@@ -1,3 +1,11 @@ +Sat Apr 20 02:09:46 2013 Martin Bosslet <Martin.Bosslet@gmail.com> + + * 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@google.com> * 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) @@ -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 |