* 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
This commit is contained in:
emboss 2013-04-15 02:04:07 +00:00
Родитель e4f6efcc4a
Коммит d6b1ab91dc
3 изменённых файлов: 45 добавлений и 4 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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)