Skip to content

Commit 42241cd

Browse files
committed
not worth checking for Ruby 2.3 to raise from sysread(4, exception: false)
1 parent 6a95403 commit 42241cd

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/main/java/org/jruby/ext/openssl/SSLSocket.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ public IRubyObject sysread_nonblock(ThreadContext context, IRubyObject len) {
795795
@JRubyMethod
796796
public IRubyObject sysread_nonblock(ThreadContext context, IRubyObject len, IRubyObject arg) {
797797
if ( arg instanceof RubyHash ) { // exception: false
798+
// NOTE: on Ruby 2.3 this is expected to raise a TypeError (but not on 2.2)
798799
return sysreadImpl(context, len, null, false, getExceptionOpt(context, arg));
799800
}
800801
return sysreadImpl(context, len, arg, false, true); // buffer arg

src/test/ruby/ssl/test_helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,20 @@ def server_loop(context, server, server_proc)
127127
rescue Errno::EBADF, IOError, Errno::EINVAL, Errno::ECONNABORTED, Errno::ENOTSOCK, Errno::ECONNRESET
128128
end
129129

130+
def server_connect(port, ctx = nil)
131+
sock = TCPSocket.new('127.0.0.1', port)
132+
ssl = ctx ? OpenSSL::SSL::SSLSocket.new(sock, ctx) : OpenSSL::SSL::SSLSocket.new(sock)
133+
ssl.sync_close = true
134+
ssl.connect
135+
yield ssl if block_given?
136+
ensure
137+
if ssl
138+
ssl.close
139+
elsif sock
140+
sock.close
141+
end
142+
end
143+
130144
def starttls(ssl)
131145
ssl.puts("STARTTLS")
132146
#sleep 1 # When this line is eliminated, process on Cygwin blocks

src/test/ruby/ssl/test_socket.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: false
12
require File.expand_path('test_helper', File.dirname(__FILE__))
23

34
class TestSSLSocket < TestCase
@@ -54,4 +55,20 @@ def test_sync_close_without_connect
5455
end
5556
end
5657

58+
include SSLTestHelper
59+
60+
def test_ssl_sysread_blocking_error
61+
start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true) do |server, port|
62+
server_connect(port) do |ssl|
63+
ssl.write("abc\n")
64+
# assert_raise(TypeError) { ssl.sysread(4, exception: false) }
65+
buf = ''
66+
assert_raise(ArgumentError) { ssl.sysread(4, buf, exception: false) }
67+
assert_equal '', buf
68+
assert_equal buf.object_id, ssl.sysread(4, buf).object_id
69+
assert_equal "abc\n", buf
70+
end
71+
end
72+
end if RUBY_VERSION > '2.0'
73+
5774
end

0 commit comments

Comments
 (0)