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 <thiago.macieira@intel.com>
Reviewed-by: Peter Hartmann <peter.hartmann@nokia.com>
This commit is contained in:
Richard Moore 2011-12-02 18:10:59 +00:00 committed by Qt by Nokia
parent 47df122259
commit 2757a5fe8c
2 changed files with 17 additions and 0 deletions

View File

@ -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

View File

@ -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)