Blob Blame History Raw
From 122c80853a9bd66f21699fc79a689b3028d00d3b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Fri, 17 Aug 2018 13:08:44 +0200
Subject: [PATCH] Move SSL_ERROR_WANT_READ/SSL_ERROR_WANT_WRITE retry from
 write_partial()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Original OpenSSL 1.1.1 fix broke IO-Socket-SSL-2.058's t/nonblock.t test
because it tests non-blocking socket operations and expects to see
SSL_ERROR_WANT_WRITE errors and to handle them byt itself.

This patch purifies Net::SSLeay::write_partial() to behave exactly as
underlying OpenSSL SSL_write() function. The retry is already
presented in Net::SSLeay::ssl_write_all().

All applications should implement the retry themsleves or use
ssl_*_all() instead.

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 SSLeay.xs          | 16 ++--------------
 lib/Net/SSLeay.pod |  3 ++-
 2 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/SSLeay.xs b/SSLeay.xs
index 7cb6eab..fc7677f 100644
--- a/SSLeay.xs
+++ b/SSLeay.xs
@@ -2089,20 +2089,8 @@ SSL_write_partial(s,from,count,buf)
      if (len < 0) {
        croak("from beyound end of buffer");
        RETVAL = -1;
-     } else {
-	     int ret;
-	     int err;
-
-	     do {
-		     ret = SSL_write (s, &(buf[from]), (count<=len)?count:len);
-		     if (ret > 0)
-			     break;
-		     err = SSL_get_error(s, ret);
-		     if (err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
-			     break;
-	     } while (1);
-	     RETVAL = ret;
-     }
+     } else
+       RETVAL = SSL_write (s, &(buf[from]), (count<=len)?count:len);
      OUTPUT:
      RETVAL
 
diff --git a/lib/Net/SSLeay.pod b/lib/Net/SSLeay.pod
index bca7be4..8b5f738 100644
--- a/lib/Net/SSLeay.pod
+++ b/lib/Net/SSLeay.pod
@@ -4819,7 +4819,8 @@ Check openssl doc L<http://www.openssl.org/docs/ssl/SSL_write.html|http://www.op
 
 B<NOTE:> Does not exactly correspond to any low level API function
 
-Writes a fragment of data in $data from the buffer $data into the specified $ssl connection.
+Writes a fragment of data in $data from the buffer $data into the specified
+$ssl connection. This is a non-blocking function like L<Net::SSLeay::write()>.
 
  my $rv = Net::SSLeay::write_partial($ssl, $from, $count, $data);
  # $ssl - value corresponding to openssl's SSL structure
-- 
2.14.4