Skip to content

Commit

Permalink
Merge pull request #467 from ruby/reject-bad-params
Browse files Browse the repository at this point in the history
Raise an exception if the IO object passed to SSLSocket isn't a file
  • Loading branch information
rhenium authored Oct 23, 2021
2 parents e0718e4 + 919fa44 commit c2cc78a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/openssl/ossl_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,7 @@ ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)

if (rb_respond_to(io, rb_intern("nonblock=")))
rb_funcall(io, rb_intern("nonblock="), 1, Qtrue);
Check_Type(io, T_FILE);
rb_ivar_set(self, id_i_io, io);

ssl = SSL_new(ctx);
Expand Down
11 changes: 11 additions & 0 deletions test/openssl/test_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
if defined?(OpenSSL)

class OpenSSL::TestSSL < OpenSSL::SSLTestCase
def test_bad_socket
bad_socket = Struct.new(:sync).new
assert_raises TypeError do
socket = OpenSSL::SSL::SSLSocket.new bad_socket
# if the socket is not a T_FILE, `connect` will segv because it tries
# to get the underlying file descriptor but the API it calls assumes
# the object type is T_FILE
socket.connect
end
end

def test_ctx_options
ctx = OpenSSL::SSL::SSLContext.new

Expand Down

0 comments on commit c2cc78a

Please sign in to comment.