]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
tls-gnutls.c: Handle rehandshake error in `_httpTLSRead` 1508/head
authorZdenek Dohnal <zdohnal@redhat.com>
Mon, 9 Mar 2026 14:18:10 +0000 (15:18 +0100)
committerZdenek Dohnal <zdohnal@redhat.com>
Mon, 9 Mar 2026 14:18:10 +0000 (15:18 +0100)
Per GNUTLS manual, `gnutls_record_recv()` can get GNUTLS_E_REHANDSHAKE
and if it is HTTP client, we should not close the connection and ignore
the error. The server can terminate the connection as before.

cups/tls-gnutls.c

index 356cebec68c0a4a7817e2b2516c3d283e9565295..f7ac74952e168507afe47bcc5a9211bd4dbfc89a 100644 (file)
@@ -1623,12 +1623,25 @@ _httpTLSRead(http_t *http,              // I - Connection to server
          break;
 
       case GNUTLS_E_AGAIN :
-          errno = EAGAIN;
-          break;
+         errno = EAGAIN;
+         break;
+
+      case GNUTLS_E_REHANDSHAKE :
+         // If used in client, ignore the error and try to read again...
+         if (http->mode == _HTTP_MODE_CLIENT)
+         {
+           errno = EAGAIN;
+         }
+         else
+         {
+           // Terminate the session as server...
+           errno = EPIPE;
+         }
+         break;
 
       default :
-          errno = EPIPE;
-          break;
+         errno = EPIPE;
+         break;
     }
 
     result = -1;
@@ -2032,12 +2045,12 @@ _httpTLSWrite(http_t     *http,         // I - Connection to server
          break;
 
       case GNUTLS_E_AGAIN :
-          errno = EAGAIN;
-          break;
+         errno = EAGAIN;
+         break;
 
       default :
-          errno = EPIPE;
-          break;
+         errno = EPIPE;
+         break;
     }
 
     result = -1;