From ae58b9dec49c809b85b5404cee17946116f8a706 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Thu, 24 Sep 2020 17:13:34 +0200 Subject: [PATCH] Limit number of connected sockets from unpaired devices Thanks Matthias Gerstner for reporting this. --- core/backends/lan/lanlinkprovider.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/backends/lan/lanlinkprovider.cpp b/core/backends/lan/lanlinkprovider.cpp index a4942c653..770e7866a 100644 --- a/core/backends/lan/lanlinkprovider.cpp +++ b/core/backends/lan/lanlinkprovider.cpp @@ -46,6 +46,8 @@ #define MIN_VERSION_WITH_SSL_SUPPORT 6 +static const int MAX_UNPAIRED_CONNECTIONS = 42; + LanLinkProvider::LanLinkProvider( bool testMode, quint16 udpBroadcastPort, @@ -555,6 +557,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)) {