Skip to content

Commit c2cc78a

Browse files
authored
Merge pull request #467 from ruby/reject-bad-params
Raise an exception if the IO object passed to SSLSocket isn't a file
2 parents e0718e4 + 919fa44 commit c2cc78a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

ext/openssl/ossl_ssl.c

+1
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,7 @@ ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)
15271527

15281528
if (rb_respond_to(io, rb_intern("nonblock=")))
15291529
rb_funcall(io, rb_intern("nonblock="), 1, Qtrue);
1530+
Check_Type(io, T_FILE);
15301531
rb_ivar_set(self, id_i_io, io);
15311532

15321533
ssl = SSL_new(ctx);

test/openssl/test_ssl.rb

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
if defined?(OpenSSL)
55

66
class OpenSSL::TestSSL < OpenSSL::SSLTestCase
7+
def test_bad_socket
8+
bad_socket = Struct.new(:sync).new
9+
assert_raises TypeError do
10+
socket = OpenSSL::SSL::SSLSocket.new bad_socket
11+
# if the socket is not a T_FILE, `connect` will segv because it tries
12+
# to get the underlying file descriptor but the API it calls assumes
13+
# the object type is T_FILE
14+
socket.connect
15+
end
16+
end
17+
718
def test_ctx_options
819
ctx = OpenSSL::SSL::SSLContext.new
920

0 commit comments

Comments
 (0)