Limit number of connected sockets from unpaired devices

Thanks Matthias Gerstner <mgerstner@suse.de> for reporting this.
This commit is contained in:
Albert Vaca Cintora 2020-09-24 17:13:34 +02:00
parent 721ba9faaf
commit ae58b9dec4

View file

@ -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)) {