Skip to content

Commit

Permalink
[qtnetwork] Error gracefully when server closes TLS connection before…
Browse files Browse the repository at this point in the history
… handshake completes. Fixes JB#53591.

If the server closes a TLS connection before the handshake completes
(which can happen, for example, if the server doesn't support TLS
connections) a retry is attempted on a null protocol handler. This
causes a segfault.

This change returns a RemoteHostClosedError instead of retrying, thereby
avoiding the segfault.
  • Loading branch information
llewelld committed Mar 26, 2021
1 parent 02f71e8 commit 5247c50
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/network/access/qhttpnetworkconnectionchannel.cpp
Expand Up @@ -860,7 +860,9 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
} else if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) {
// Try to reconnect/resend before sending an error.
// While "Reading" the _q_disconnected() will handle this.
if (reconnectAttempts-- > 0) {
// If the protocolHandler hasn't been set up on a TLS connection by this point, it's because
// the connection was closed before the handshake completed and we shouldn't retry.
if (reconnectAttempts-- > 0 && (!ssl || protocolHandler)) {
resendCurrentRequest();
return;
} else {
Expand Down

0 comments on commit 5247c50

Please sign in to comment.