summaryrefslogtreecommitdiff
path: root/ext
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 /ext
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
Diffstat (limited to 'ext')
-rw-r--r--ext/openssl/ossl_ssl.c8
1 files changed, 7 insertions, 1 deletions
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;