Skip to content

Commit

Permalink
Limit number of connected sockets from unpaired devices
Browse files Browse the repository at this point in the history
Thanks Matthias Gerstner <mgerstner@suse.de> for reporting this.
  • Loading branch information
albertvaka committed Oct 2, 2020
1 parent 8112729 commit 542d94a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/backends/lan/lanlinkprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#define MIN_VERSION_WITH_SSL_SUPPORT 6

static const int MAX_UNPAIRED_CONNECTIONS = 42;

LanLinkProvider::LanLinkProvider(
bool testMode,
quint16 udpBroadcastPort,
Expand Down Expand Up @@ -580,6 +582,15 @@ void LanLinkProvider::addLink(const QString& deviceId, QSslSocket* socket, Netwo
deviceLink->reset(socket, connectionOrigin);
} else {
deviceLink = new LanDeviceLink(deviceId, this, socket, connectionOrigin);
// Socket disconnection will now be handled by LanDeviceLink
disconnect(socket, &QAbstractSocket::disconnected, socket, &QObject::deleteLater);
bool isDeviceTrusted = KdeConnectConfig::instance().trustedDevices().contains(deviceId);
if (!isDeviceTrusted && m_links.size() > MAX_UNPAIRED_CONNECTIONS) {
qCWarning(KDECONNECT_CORE) << "Too many unpaired devices to remember them all. Ignoring " << deviceId;
socket->disconnectFromHost();
socket->deleteLater();
return;
}
connect(deviceLink, &QObject::destroyed, this, &LanLinkProvider::deviceLinkDestroyed);
m_links[deviceId] = deviceLink;
if (m_pairingHandlers.contains(deviceId)) {
Expand Down

0 comments on commit 542d94a

Please sign in to comment.