summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2015-09-25 13:23:46 +0200
committerMarkus Goetz (Woboq GmbH) <markus@woboq.com>2015-11-05 08:40:57 +0000
commit7aba75ffc52e5dce4b3ada12668611be2ad6787e (patch)
treebea89e4b84b9bc3af82410a66de9e0e3977f3610 /src
parentc69f75426d004d7cdadf51ea06238fef98493ec7 (diff)
Don't let closed http sockets pass as valid connections
A QAbstractSocket can be close()'d at any time, independently of its current connection state. being closed means that we cannot use it to read or write data, but internally it might still have some data to send or receive, for example to an http server. We can even get a connected() signal after close()'ing the socket. We need to catch this condition and mark any pending data not yet written to the socket for resending. (cherry picked from commit 0df5d079290b4c3b13e58e9397fabdc1dfdba96b) Task-number: QTBUG-48326 Change-Id: I67d9ad36f7288c9c6bef51aa6253d7b187737601 Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com> Reviewed-by: Markus Goetz (Woboq GmbH) <markus@woboq.com>
Diffstat (limited to 'src')
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
index 0820a8d63e..453a0c71b6 100644
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
@@ -272,7 +272,12 @@ bool QHttpNetworkConnectionChannel::ensureConnection()
QAbstractSocket::SocketState socketState = socket->state();
// resend this request after we receive the disconnected signal
- if (socketState == QAbstractSocket::ClosingState) {
+ // If !socket->isOpen() then we have already called close() on the socket, but there was still a
+ // pending connectToHost() for which we hadn't seen a connected() signal, yet. The connected()
+ // has now arrived (as indicated by socketState != ClosingState), but we cannot send anything on
+ // such a socket anymore.
+ if (socketState == QAbstractSocket::ClosingState ||
+ (socketState != QAbstractSocket::UnconnectedState && !socket->isOpen())) {
if (reply)
resendCurrent = true;
return false;