From a9e98cf7d4bf7b551a5b88e0c687b2f58a2f5510 Mon Sep 17 00:00:00 2001 From: nagachika Date: Thu, 18 Aug 2016 14:54:40 +0000 Subject: 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_3@55961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/openssl/ossl_ssl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index b30c2cbf07..f220379872 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -1533,7 +1533,13 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts) 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; -- cgit v1.2.3