From 2757a5fe8cdfe7e23bc8a609b89d47b08d39c0bc Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Fri, 2 Dec 2011 18:10:59 +0000 Subject: [PATCH] Check we're connected before startClientEncryption() The docs say this is required, but we don't check it and instead segfault right now. Change-Id: I825b00a312a481c5383af127333c0c4698188348 Reviewed-by: Thiago Macieira Reviewed-by: Peter Hartmann --- src/network/ssl/qsslsocket.cpp | 4 ++++ tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index 05f50af..e3dd6ae 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -1630,6 +1630,10 @@ void QSslSocket::startClientEncryption() qWarning("QSslSocket::startClientEncryption: cannot start handshake on non-plain connection"); return; } + if (state() != ConnectedState) { + qWarning("QSslSocket::startClientEncryption: cannot start handshake when not connected"); + return; + } #ifdef QSSLSOCKET_DEBUG qDebug() << "QSslSocket::startClientEncryption()"; #endif diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index 378aff9..a83611e 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -195,6 +195,7 @@ private slots: void setEmptyDefaultConfiguration(); void versionAccessors(); void sslOptions(); + void encryptWithoutConnecting(); static void exitLoop() { @@ -2122,6 +2123,18 @@ void tst_QSslSocket::sslOptions() #endif } +void tst_QSslSocket::encryptWithoutConnecting() +{ + if (!QSslSocket::supportsSsl()) + return; + + QTest::ignoreMessage(QtWarningMsg, + "QSslSocket::startClientEncryption: cannot start handshake when not connected"); + + QSslSocket sock; + sock.startClientEncryption(); +} + #endif // QT_NO_OPENSSL QTEST_MAIN(tst_QSslSocket) -- 2.7.4