Protect the access to IDevice::sshParameters()

May be called in non-gui threads while it may be
changed from settings widget at the same time.

Change-Id: I2897fc2e54336b9043213411cb620896bbecde86
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-02-21 17:29:50 +01:00
parent cc139b768f
commit f1e0ca643e

View File

@@ -45,6 +45,7 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <QDateTime> #include <QDateTime>
#include <QReadWriteLock>
#include <QString> #include <QString>
#include <QUuid> #include <QUuid>
@@ -151,6 +152,7 @@ public:
OsType osType = OsTypeOther; OsType osType = OsTypeOther;
int version = 0; // This is used by devices that have been added by the SDK. int version = 0; // This is used by devices that have been added by the SDK.
QReadWriteLock lock; // Currently used to protect sshParameters only
QSsh::SshConnectionParameters sshParameters; QSsh::SshConnectionParameters sshParameters;
PortList freePorts; PortList freePorts;
FilePath debugServerPath; FilePath debugServerPath;
@@ -636,6 +638,7 @@ void IDevice::fromMap(const QVariantMap &map)
d->id = newId(); d->id = newId();
d->origin = static_cast<Origin>(map.value(QLatin1String(OriginKey), ManuallyAdded).toInt()); d->origin = static_cast<Origin>(map.value(QLatin1String(OriginKey), ManuallyAdded).toInt());
QWriteLocker locker(&d->lock);
d->sshParameters.setHost(map.value(QLatin1String(HostKey)).toString()); d->sshParameters.setHost(map.value(QLatin1String(HostKey)).toString());
d->sshParameters.setPort(map.value(QLatin1String(SshPortKey), 22).toInt()); d->sshParameters.setPort(map.value(QLatin1String(SshPortKey), 22).toInt());
d->sshParameters.setUserName(map.value(QLatin1String(UserNameKey)).toString()); d->sshParameters.setUserName(map.value(QLatin1String(UserNameKey)).toString());
@@ -680,6 +683,7 @@ QVariantMap IDevice::toMap() const
map.insert(QLatin1String(IdKey), d->id.toSetting()); map.insert(QLatin1String(IdKey), d->id.toSetting());
map.insert(QLatin1String(OriginKey), d->origin); map.insert(QLatin1String(OriginKey), d->origin);
QReadLocker locker(&d->lock);
map.insert(QLatin1String(MachineTypeKey), d->machineType); map.insert(QLatin1String(MachineTypeKey), d->machineType);
map.insert(QLatin1String(HostKey), d->sshParameters.host()); map.insert(QLatin1String(HostKey), d->sshParameters.host());
map.insert(QLatin1String(SshPortKey), d->sshParameters.port()); map.insert(QLatin1String(SshPortKey), d->sshParameters.port());
@@ -730,11 +734,13 @@ QString IDevice::deviceStateToString() const
QSsh::SshConnectionParameters IDevice::sshParameters() const QSsh::SshConnectionParameters IDevice::sshParameters() const
{ {
QReadLocker locker(&d->lock);
return d->sshParameters; return d->sshParameters;
} }
void IDevice::setSshParameters(const QSsh::SshConnectionParameters &sshParameters) void IDevice::setSshParameters(const QSsh::SshConnectionParameters &sshParameters)
{ {
QWriteLocker locker(&d->lock);
d->sshParameters = sshParameters; d->sshParameters = sshParameters;
} }
@@ -742,6 +748,7 @@ QUrl IDevice::toolControlChannel(const ControlChannelHint &) const
{ {
QUrl url; QUrl url;
url.setScheme(Utils::urlTcpScheme()); url.setScheme(Utils::urlTcpScheme());
QReadLocker locker(&d->lock);
url.setHost(d->sshParameters.host()); url.setHost(d->sshParameters.host());
return url; return url;
} }