aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_pair.rb
diff options
context:
space:
mode:
authornormal <normal@ruby-lang.org>2016-08-06 21:50:10 +0000
committerKazuki Yamaguchi <k@rhe.jp>2016-08-07 17:17:23 +0900
commitdbfe97c1e6081a56cae78f86a0d0c8a457c3c1c2 (patch)
tree5a2215ec21507282ec41b7c7c26806e84149767c /test/test_pair.rb
parent57ca27cd9ad393d37c6d5887d036cdd16b739150 (diff)
downloadruby-openssl-dbfe97c1e6081a56cae78f86a0d0c8a457c3c1c2.tar.gz
openssl: avoid undefined behavior on empty SSL_write
SSL_write(3ssl) manpage has this in the WARNINGS section: When calling SSL_write() with num=0 bytes to be sent the behaviour is undefined. And indeed, the new test case demonstrates failures when empty strings are used. So, match the behavior of IO#write, IO#write_nonblock, and IO#syswrite by returning zero, as the OpenSSL::SSL::SSLSocket API already closely mimics the IO one. * ext/openssl/ossl_ssl.c (ossl_ssl_write_internal): avoid undefined behavior * test/openssl/test_pair.rb (test_write_zero): new test [ruby-core:76751] [Bug #12660] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/test_pair.rb')
-rw-r--r--test/test_pair.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/test_pair.rb b/test/test_pair.rb
index ee43a0c6..610aa982 100644
--- a/test/test_pair.rb
+++ b/test/test_pair.rb
@@ -311,6 +311,17 @@ module OpenSSL::TestPairM
}
end
+ def test_write_zero
+ ssl_pair {|s1, s2|
+ assert_equal 0, s2.write_nonblock('', exception: false)
+ assert_kind_of Symbol, s1.read_nonblock(1, exception: false)
+ assert_equal 0, s2.syswrite('')
+ assert_kind_of Symbol, s1.read_nonblock(1, exception: false)
+ assert_equal 0, s2.write('')
+ assert_kind_of Symbol, s1.read_nonblock(1, exception: false)
+ }
+ end
+
def tcp_pair
host = "127.0.0.1"
serv = TCPServer.new(host, 0)