summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-30 15:03:15 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-30 15:03:15 +0000
commitc880452b7cdb1132a86974f621deb49388aad1fb (patch)
treec65ccf757d224a1f705988ac41a822022d053258
parent81d5b699812dab4048543da77a40372bd4b4045c (diff)
merge revision(s) 55822: [Backport #12660]
* 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/branches/ruby_2_2@56300 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--ext/openssl/ossl_ssl.c8
-rw-r--r--test/openssl/test_pair.rb11
-rw-r--r--version.h8
4 files changed, 29 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index d6715b4275..908f5fb370 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sat Oct 1 00:00:13 2016 Eric Wong <e@80x24.org>
+
+ * 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]
+
Tue Aug 16 21:12:07 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compile.c (ADD_TRACE): ignore trace instruction on non-positive
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 6857b353f5..f00576bca3 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1539,7 +1539,13 @@ ossl_ssl_write_internal(VALUE self, VALUE str, int nonblock, int no_exception)
if (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/openssl/test_pair.rb b/test/openssl/test_pair.rb
index 3aca5f4833..ea5b917d7f 100644
--- a/test/openssl/test_pair.rb
+++ b/test/openssl/test_pair.rb
@@ -271,6 +271,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)
diff --git a/version.h b/version.h
index 5c30bcb98d..e3f866936a 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.2.6"
-#define RUBY_RELEASE_DATE "2016-08-16"
-#define RUBY_PATCHLEVEL 369
+#define RUBY_RELEASE_DATE "2016-10-01"
+#define RUBY_PATCHLEVEL 370
#define RUBY_RELEASE_YEAR 2016
-#define RUBY_RELEASE_MONTH 8
-#define RUBY_RELEASE_DAY 16
+#define RUBY_RELEASE_MONTH 10
+#define RUBY_RELEASE_DAY 1
#include "ruby/version.h"