diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2021-10-23 13:28:09 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-23 13:28:09 +0900 |
commit | c2cc78a8f5ca294325630600dd0dd59f8fedc927 (patch) | |
tree | 1d9ce7337f7e1aa16a78e940b1078f6bbbae303e | |
parent | e0718e4d2c0f751719e136f3cb79616daa3f6686 (diff) | |
parent | 919fa44ec2c011f595f7a32a222220f41a131338 (diff) | |
download | ruby-openssl-c2cc78a8f5ca294325630600dd0dd59f8fedc927.tar.gz |
Merge pull request #467 from ruby/reject-bad-params
Raise an exception if the IO object passed to SSLSocket isn't a file
-rw-r--r-- | ext/openssl/ossl_ssl.c | 1 | ||||
-rw-r--r-- | test/openssl/test_ssl.rb | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index d6d321e4..1de0f989 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -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); diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb index 6412250c..15e8d7e3 100644 --- a/test/openssl/test_ssl.rb +++ b/test/openssl/test_ssl.rb @@ -4,6 +4,17 @@ require_relative "utils" 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 |