]> granicus.if.org Git - mutt/commitdiff
Fix gnutls tls_socket_write() to properly retry.
authorKevin McCarthy <kevin@8t8.us>
Mon, 21 Jan 2019 19:56:04 +0000 (11:56 -0800)
committerKevin McCarthy <kevin@8t8.us>
Mon, 21 Jan 2019 19:56:04 +0000 (11:56 -0800)
Retry on GNUTLS_E_AGAIN and GNUTLS_E_INTERRUPTED.  This prevents an
aborted send due to a SIGWINCH, for instance.

Change tls_socket_read() to follow the same flow.  Don't bother
checking gnutls_error_is_fatal() because return codes besides AGAIN
and INTERRUPTED end up closing the connection regardless.  (We don't
handle handshakes and negotations during send/receive).

mutt_ssl_gnutls.c

index bc9460d9a07e3ede9f91b8853b96050e0a67235b..e4730a18404363d527fe69b2aa5dc695622bc157 100644 (file)
@@ -140,16 +140,17 @@ static int tls_socket_read (CONNECTION* conn, char* buf, size_t len)
     return -1;
   }
 
-  do {
+  do
+  {
     ret = gnutls_record_recv (data->state, buf, len);
-    if (ret < 0 && gnutls_error_is_fatal(ret) == 1)
-    {
-      mutt_error ("tls_socket_read (%s)", gnutls_strerror (ret));
-      mutt_sleep (4);
-      return -1;
-    }
+  } while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+
+  if (ret < 0)
+  {
+    mutt_error ("tls_socket_read (%s)", gnutls_strerror (ret));
+    mutt_sleep (4);
+    return -1;
   }
-  while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
 
   return ret;
 }
@@ -169,17 +170,18 @@ static int tls_socket_write (CONNECTION* conn, const char* buf, size_t len)
 
   do
   {
-    ret = gnutls_record_send (data->state, buf + sent, len - sent);
+    do
+    {
+      ret = gnutls_record_send (data->state, buf + sent, len - sent);
+    } while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+
     if (ret < 0)
     {
-      if (gnutls_error_is_fatal(ret) == 1)
-      {
-       mutt_error ("tls_socket_write (%s)", gnutls_strerror (ret));
-       mutt_sleep (4);
-       return -1;
-      }
-      return ret;
+      mutt_error ("tls_socket_write (%s)", gnutls_strerror (ret));
+      mutt_sleep (4);
+      return -1;
     }
+
     sent += ret;
   } while (sent < len);