diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2009-08-18 06:33:09 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2009-08-18 06:34:12 (GMT) |
commit | f30e54f2e8f89ca2c92032457a98b3f98010ba44 (patch) | |
tree | 30da13df4d7bebd6d5f114cf477eb74e5507367e | |
parent | 95cb2bb6cbdf2dcc0a035105104a4c08ecc43e83 (diff) | |
download | Qt-f30e54f2e8f89ca2c92032457a98b3f98010ba44.zip Qt-f30e54f2e8f89ca2c92032457a98b3f98010ba44.tar.gz Qt-f30e54f2e8f89ca2c92032457a98b3f98010ba44.tar.bz2 |
QSslSocket: Clear readBuffer and writeBuffer on close()
Fixes https://bugs.webkit.org/show_bug.cgi?id=28016
Reviewed-by: andreas
-rw-r--r-- | src/network/ssl/qsslsocket.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qsslsocket/tst_qsslsocket.cpp | 29 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index e8ae33d..1acd88b 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -653,7 +653,16 @@ void QSslSocket::close() #ifdef QSSLSOCKET_DEBUG qDebug() << "QSslSocket::close()"; #endif + Q_D(QSslSocket); QTcpSocket::close(); + + // must be cleared, reading/writing not possible on closed socket: + d->readBuffer.clear(); + d->writeBuffer.clear(); + // for QTcpSocket this is already done because it uses the readBuffer/writeBuffer + // if the QIODevice it is based on + // ### FIXME QSslSocket should probably do similar instead of having + // its own readBuffer/writeBuffer } /*! diff --git a/tests/auto/qsslsocket/tst_qsslsocket.cpp b/tests/auto/qsslsocket/tst_qsslsocket.cpp index 4f466a1..f3bc4c4 100644 --- a/tests/auto/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/qsslsocket/tst_qsslsocket.cpp @@ -172,6 +172,7 @@ private slots: void disconnectFromHostWhenConnecting(); void disconnectFromHostWhenConnected(); void resetProxy(); + void readFromClosedSocket(); static void exitLoop() { @@ -1508,6 +1509,34 @@ void tst_QSslSocket::resetProxy() QVERIFY2(socket2.waitForConnected(10000), qPrintable(socket.errorString())); } +// make sure a closed socket has no bytesAvailable() +// related to https://bugs.webkit.org/show_bug.cgi?id=28016 +void tst_QSslSocket::readFromClosedSocket() +{ + QSslSocketPtr socket = newSocket(); + socket->ignoreSslErrors(); + socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); + socket->ignoreSslErrors(); + socket->waitForConnected(); + socket->waitForEncrypted(); + // provoke a response by sending a request + socket->write("GET /gif/fluke.gif HTTP/1.1\n"); + socket->write("Host: "); + socket->write(QtNetworkSettings::serverName().toLocal8Bit().constData()); + socket->write("\n"); + socket->write("\n"); + socket->waitForBytesWritten(); + socket->waitForReadyRead(); + QVERIFY(socket->state() == QAbstractSocket::ConnectedState); + QVERIFY(socket->bytesAvailable()); + socket->close(); + QVERIFY(!socket->bytesAvailable()); + QVERIFY(!socket->bytesToWrite()); + socket->waitForDisconnected(); + QVERIFY(!socket->bytesAvailable()); + QVERIFY(!socket->bytesToWrite()); +} + #endif // QT_NO_OPENSSL QTEST_MAIN(tst_QSslSocket) |