Description: Fix handling of non-fatal errors in gnutls_handshake
Author: Emmanuel Bouthenot <kolter@debian.org>
Bug-Debian: https://bugs.debian.org/785135
Applied-Upstream: http://sourceforge.net/p/msmtp/code/ci/7f952bf19cef450b3d84971e96798742de5c7b60
Last-Update: 2015-05-25
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/tls.c
+++ b/src/tls.c
@@ -1356,24 +1356,16 @@
     int error_code;
 
     gnutls_transport_set_ptr(tls->session, (gnutls_transport_ptr_t)fd);
-    if ((error_code = gnutls_handshake(tls->session)) < 0)
+    do
     {
-        if (error_code == GNUTLS_E_INTERRUPTED)
-        {
-            *errstr = xasprintf(_("operation aborted"));
-        }
-        else if (error_code == GNUTLS_E_AGAIN)
-        {
-            /* This error message makes more sense than what
-             * gnutls_strerror() would return. */
-            *errstr = xasprintf(_("TLS handshake failed: %s"),
-                    _("the operation timed out"));
-        }
-        else
-        {
-            *errstr = xasprintf(_("TLS handshake failed: %s"),
-                    gnutls_strerror(error_code));
-        }
+        error_code = gnutls_handshake(tls->session);
+    }
+    while (error_code < 0 && gnutls_error_is_fatal(error_code) == 0);
+
+    if (error_code != 0)
+    {
+        *errstr = xasprintf(_("TLS handshake failed: %s"),
+                gnutls_strerror(error_code));
         gnutls_deinit(tls->session);
         gnutls_certificate_free_credentials(tls->cred);
         return TLS_EHANDSHAKE;
