Skip to content

Commit 84eb620

Browse files
committed
[BB10-internal] SSL internals: fix memory corruption using QSslConfigurationPrivate
We are passing a QSslConfigurationPrivate that is allocated on the stack (in QSslSocketBackendPrivate::initSslContext()) to QSslConfiguration::QSslConfiguration(QSslConfigurationPrivate *dd). When the SSL context is destroyed, this object is not there any more. So now we create a deep copy of the configuration like we do in QSslSocket::sslConfiguration(). Task-number: QTBUG-30648 (backport of commit 3a43aff9deb4af0479914a26d68fb98d313369b6) Signed-off-by: Peter Hartmann <[email protected]> Change-Id: I0a39b2bc485ce5a3528b72e6e47c3bd124963b3b
1 parent c440da5 commit 84eb620

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/network/ssl/qsslsocket_openssl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,13 @@ bool QSslSocketBackendPrivate::initSslContext()
249249
Q_Q(QSslSocket);
250250

251251
// If no external context was set (e.g. bei QHttpNetworkConnection) we will create a default context
252-
if (!sslContextPointer)
252+
if (!sslContextPointer) {
253+
// create a deep copy of our configuration
254+
QSslConfigurationPrivate *configurationCopy = new QSslConfigurationPrivate(configuration);
255+
configurationCopy->ref = 0; // the QSslConfiguration constructor refs up
253256
sslContextPointer = QSharedPointer<QSslContext>(
254-
QSslContext::fromConfiguration(mode, QSslConfiguration(&configuration), allowRootCertOnDemandLoading));
257+
QSslContext::fromConfiguration(mode, configurationCopy, allowRootCertOnDemandLoading));
258+
}
255259

256260
if (sslContextPointer->error() != QSslError::NoError) {
257261
q->setErrorString(sslContextPointer->errorString());

0 commit comments

Comments
 (0)