Skip to content

Commit 0fe488a

Browse files
committed
tls-gnutls.c: Handle rehandshake error in _httpTLSRead
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.
1 parent 15e073c commit 0fe488a

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

cups/tls-gnutls.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,25 +1613,37 @@ _httpTLSRead(http_t *http, // I - Connection to server
16131613

16141614
result = gnutls_record_recv(http->tls, buf, (size_t)len);
16151615

1616+
// Convert GNU TLS error to errno value...
16161617
if (result < 0)
16171618
{
1618-
// Convert GNU TLS error to errno value...
16191619
switch (result)
16201620
{
16211621
case GNUTLS_E_INTERRUPTED :
16221622
errno = EINTR;
16231623
break;
16241624

16251625
case GNUTLS_E_AGAIN :
1626-
errno = EAGAIN;
1627-
break;
1626+
errno = EAGAIN;
1627+
break;
1628+
1629+
case GNUTLS_E_REHANDSHAKE :
1630+
// if used in client, ignore the error
1631+
if (http->mode == _HTTP_MODE_CLIENT)
1632+
{
1633+
errno = 0;
1634+
result = 0;
1635+
}
1636+
else
1637+
{
1638+
// terminate the session as server
1639+
errno = EPIPE;
1640+
}
1641+
break;
16281642

16291643
default :
1630-
errno = EPIPE;
1631-
break;
1644+
errno = EPIPE;
1645+
break;
16321646
}
1633-
1634-
result = -1;
16351647
}
16361648

16371649
return ((int)result);
@@ -2032,15 +2044,13 @@ _httpTLSWrite(http_t *http, // I - Connection to server
20322044
break;
20332045

20342046
case GNUTLS_E_AGAIN :
2035-
errno = EAGAIN;
2036-
break;
2047+
errno = EAGAIN;
2048+
break;
20372049

20382050
default :
2039-
errno = EPIPE;
2040-
break;
2051+
errno = EPIPE;
2052+
break;
20412053
}
2042-
2043-
result = -1;
20442054
}
20452055

20462056
DEBUG_printf("5_httpTLSWrite: Returning %d.", (int)result);

0 commit comments

Comments
 (0)