summaryrefslogtreecommitdiffstats
path: root/src/plugins/tls
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2024-02-21 17:35:58 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2024-02-27 15:18:06 +0000
commit74f16c0ed5f0e0bb05e8a9b40266524cec8e4257 (patch)
tree507d2fb7774fc7271c43a7c4c870b535665b401f /src/plugins/tls
parent3044a8ae274e579b4eab9c9564482314eb7e3f29 (diff)
Schannel: check that plainsocket is open before use
In reality I think it should be covered elsewhere, before reaching the TLS code. But this is a simple fix to avoid an unnecessary warning. This is actually quite similar to the resolution in ef4ba0285f9c5dd5ee2dca1e0cefee45eba3477c. Technically checking isWritable would be more correct, but Qt is usually the one to open the socket, and we open for both read and write anyway. Fixes: QTBUG-116550 Pick-to: 6.7 6.6 6.5 Change-Id: I4996b18b5b65c434d91543451186f335e201604f Reviewed-by: Mate Barany <mate.barany@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/plugins/tls')
-rw-r--r--src/plugins/tls/schannel/qtls_schannel.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/plugins/tls/schannel/qtls_schannel.cpp b/src/plugins/tls/schannel/qtls_schannel.cpp
index d42aea42d0..eba152d159 100644
--- a/src/plugins/tls/schannel/qtls_schannel.cpp
+++ b/src/plugins/tls/schannel/qtls_schannel.cpp
@@ -1023,8 +1023,10 @@ bool TlsCryptographSchannel::sendToken(void *token, unsigned long tokenLength, b
Q_ASSERT(d);
auto *plainSocket = d->plainTcpSocket();
Q_ASSERT(plainSocket);
- if (plainSocket->state() == QAbstractSocket::UnconnectedState || !plainSocket->isValid())
+ if (plainSocket->state() == QAbstractSocket::UnconnectedState || !plainSocket->isValid()
+ || !plainSocket->isOpen()) {
return false;
+ }
const qint64 written = plainSocket->write(static_cast<const char *>(token), tokenLength);
if (written != qint64(tokenLength)) {
@@ -1387,7 +1389,8 @@ bool TlsCryptographSchannel::performHandshake()
auto *plainSocket = d->plainTcpSocket();
Q_ASSERT(plainSocket);
- if (plainSocket->state() == QAbstractSocket::UnconnectedState || !plainSocket->isValid()) {
+ if (plainSocket->state() == QAbstractSocket::UnconnectedState || !plainSocket->isValid()
+ || !plainSocket->isOpen()) {
setErrorAndEmit(d, QAbstractSocket::RemoteHostClosedError,
QSslSocket::tr("The TLS/SSL connection has been closed"));
return false;
@@ -1763,8 +1766,10 @@ void TlsCryptographSchannel::transmit()
return; // This function should not have been called
// Can happen if called through QSslSocket::abort->QSslSocket::close->QSslSocket::flush->here
- if (plainSocket->state() == QAbstractSocket::UnconnectedState || !plainSocket->isValid())
+ if (plainSocket->state() == QAbstractSocket::UnconnectedState || !plainSocket->isValid()
+ || !plainSocket->isOpen()) {
return;
+ }
if (schannelState != SchannelState::Done) {
continueHandshake();