diff options
author | Peter Hartmann <peter.hartmann@nokia.com> | 2010-08-30 15:43:01 +0200 |
---|---|---|
committer | Samuli Piippo <samuli.piippo@digia.com> | 2011-06-09 13:06:48 +0300 |
commit | e65c62cbe572f689ae83c2bfa7d08e20c4944f07 (patch) | |
tree | e7b284460c918cd2eeb592f7547c2356e5fe33cb | |
parent | 7ea82acb7694b5791d9476def0a33868599b3fbc (diff) | |
download | qt4-tools-e65c62cbe572f689ae83c2bfa7d08e20c4944f07.tar.gz |
QSslConfiguration: fix crash when accessing null pointer
We were accessing the d-pointer of a QSslConfiguration which is
initialized lazily.
Reviewed-by: Markus Goetz
Task-number: QTBUG-13265
(cherry picked from commit d686a95ed54b19336affc14c9222de54c9af0e72)
-rw-r--r-- | src/network/ssl/qsslsocket.cpp | 5 | ||||
-rw-r--r-- | tests/auto/qsslsocket/tst_qsslsocket.cpp | 16 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index 9dcae3e508..a07469bca9 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -1966,6 +1966,11 @@ void QSslConfigurationPrivate::deepCopyDefaultConfiguration(QSslConfigurationPri QMutexLocker locker(&globalData()->mutex); const QSslConfigurationPrivate *global = globalData()->config.constData(); + if (!global) { + ptr = 0; + return; + } + ptr->ref = 1; ptr->peerCertificate = global->peerCertificate; ptr->peerCertificateChain = global->peerCertificateChain; diff --git a/tests/auto/qsslsocket/tst_qsslsocket.cpp b/tests/auto/qsslsocket/tst_qsslsocket.cpp index f9312918ac..6ae4b10d06 100644 --- a/tests/auto/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/qsslsocket/tst_qsslsocket.cpp @@ -181,6 +181,7 @@ private slots: void ignoreSslErrorsListWithSlot(); void readFromClosedSocket(); void writeBigChunk(); + void setEmptyDefaultConfiguration(); static void exitLoop() { @@ -1794,6 +1795,21 @@ void tst_QSslSocket::writeBigChunk() socket->close(); } +void tst_QSslSocket::setEmptyDefaultConfiguration() +{ + // used to produce a crash in QSslConfigurationPrivate::deepCopyDefaultConfiguration, QTBUG-13265 + + if (!QSslSocket::supportsSsl()) + return; + + QSslConfiguration emptyConf; + QSslConfiguration::setDefaultConfiguration(emptyConf); + + QSslSocketPtr socket = newSocket(); + socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); + +} + #endif // QT_NO_OPENSSL QTEST_MAIN(tst_QSslSocket) |