aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoremboss <emboss@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-15 02:04:07 +0000
committeremboss <emboss@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-15 02:04:07 +0000
commitd6b1ab91dcf83536ea7d94f2b855e8ce21802136 (patch)
treed57eaa5544f3461c9eb31a0a0120d2b738197d28
parente4f6efcc4a830b94634e2461ffbc564040344058 (diff)
downloadruby-d6b1ab91dcf83536ea7d94f2b855e8ce21802136.tar.gz
* 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/trunk@40304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--ext/openssl/ossl_ssl.c14
-rw-r--r--test/openssl/test_ssl.rb27
3 files changed, 45 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index ad4244eaf2..aafb666970 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Mon Apr 15 12:54:42 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!
+
Mon Apr 15 10:23:39 2013 NARUSE, Yui <naruse@ruby-lang.org>
* ext/coverage/depend: fix id.h place as r40283.
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index e2174034e7..ec54f9cd2a 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1119,7 +1119,6 @@ ossl_ssl_shutdown(SSL *ssl)
static void
ossl_ssl_free(SSL *ssl)
{
- ossl_ssl_shutdown(ssl);
SSL_free(ssl);
}
@@ -1538,9 +1537,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)