aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-08-07 17:17:23 +0900
committerKazuki Yamaguchi <k@rhe.jp>2016-08-07 17:17:23 +0900
commite9496bed5c37e5efcd73b3015369123ebaf4d8e8 (patch)
tree5a2215ec21507282ec41b7c7c26806e84149767c
parent57ca27cd9ad393d37c6d5887d036cdd16b739150 (diff)
parentdbfe97c1e6081a56cae78f86a0d0c8a457c3c1c2 (diff)
downloadruby-openssl-e9496bed5c37e5efcd73b3015369123ebaf4d8e8.tar.gz
Merge changes from Ruby trunk r55757..r55822
* ruby-trunk r55757..r55822: (1 commits) (r55822) openssl: avoid undefined behavior on empty SSL_write Sync-with-trunk: r55822
-rw-r--r--ext/openssl/ossl_ssl.c8
-rw-r--r--test/test_pair.rb11
2 files changed, 18 insertions, 1 deletions
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 4c0f82b3..a443c055 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1776,7 +1776,13 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
if (ssl_started(ssl)) {
for (;;){
- nwrite = SSL_write(ssl, RSTRING_PTR(str), RSTRING_LENINT(str));
+ int num = RSTRING_LENINT(str);
+
+ /* SSL_write(3ssl) manpage states num == 0 is undefined */
+ if (num == 0)
+ goto end;
+
+ nwrite = SSL_write(ssl, RSTRING_PTR(str), num);
switch(ssl_get_error(ssl, nwrite)){
case SSL_ERROR_NONE:
goto end;
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)