Skip to content
Permalink
Browse files Browse the repository at this point in the history
Do not remember more than a few identity packets at a time
To prevent the kdeconnect process from using too much memory.

Thanks Matthias Gerstner <mgerstner@suse.de> for reporting this.
  • Loading branch information
albertvaka committed Oct 2, 2020
1 parent 542d94a commit 613899b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/backends/lan/lanlinkprovider.cpp
Expand Up @@ -34,6 +34,7 @@
#define MIN_VERSION_WITH_SSL_SUPPORT 6

static const int MAX_UNPAIRED_CONNECTIONS = 42;
static const int MAX_REMEMBERED_IDENTITY_PACKETS = 42;

LanLinkProvider::LanLinkProvider(
bool testMode,
Expand Down Expand Up @@ -243,6 +244,12 @@ void LanLinkProvider::udpBroadcastReceived()

//qCDebug(KDECONNECT_CORE) << "Received Udp identity packet from" << sender << " asking for a tcp connection on port " << tcpPort;

if (m_receivedIdentityPackets.size() > MAX_REMEMBERED_IDENTITY_PACKETS) {
qCWarning(KDECONNECT_CORE) << "Too many remembered identities, ignoring" << receivedPacket->get<QString>(QStringLiteral("deviceId")) << "received via UDP";
delete receivedPacket;
continue;
}

QSslSocket* socket = new QSslSocket(this);
socket->setProxy(QNetworkProxy::NoProxy);
m_receivedIdentityPackets[socket].np = receivedPacket;
Expand Down Expand Up @@ -453,6 +460,12 @@ void LanLinkProvider::dataReceived()
return;
}

if (m_receivedIdentityPackets.size() > MAX_REMEMBERED_IDENTITY_PACKETS) {
qCWarning(KDECONNECT_CORE) << "Too many remembered identities, ignoring" << np->get<QString>(QStringLiteral("deviceId")) << "received via TCP";
delete np;
return;
}

// Needed in "encrypted" if ssl is used, similar to "tcpSocketConnected"
m_receivedIdentityPackets[socket].np = np;

Expand Down

0 comments on commit 613899b

Please sign in to comment.