Skip to content

Commit 0abb3e8

Browse files
authored
Block attempts to connect to the client (#10589)
A Minetest peer initiates a connection by sending a packet with an invalid peer_id, for whatever reason the code for doing this ran on both the client and the server meaning you could connect to a client if you knew what the address:port tuple it was listening on.
1 parent 9c9344c commit 0abb3e8

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/network/connection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ void Connection::sendAck(session_t peer_id, u8 channelnum, u16 seqnum)
15661566

15671567
UDPPeer* Connection::createServerPeer(Address& address)
15681568
{
1569-
if (getPeerNoEx(PEER_ID_SERVER) != 0)
1569+
if (ConnectedToServer())
15701570
{
15711571
throw ConnectionException("Already connected to a server");
15721572
}

src/network/connection.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,11 @@ class Connection
809809
void putEvent(ConnectionEvent &e);
810810

811811
void TriggerSend();
812+
813+
bool ConnectedToServer()
814+
{
815+
return getPeerNoEx(PEER_ID_SERVER) != nullptr;
816+
}
812817
private:
813818
MutexedQueue<ConnectionEvent> m_event_queue;
814819

src/network/connectionthreads.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,11 @@ void ConnectionReceiveThread::receive(SharedBuffer<u8> &packetdata,
956956
// command was sent reliably.
957957
}
958958

959-
/* The peer was not found in our lists. Add it. */
960959
if (peer_id == PEER_ID_INEXISTENT) {
960+
/* Ignore it if we are a client */
961+
if (m_connection->ConnectedToServer())
962+
return;
963+
/* The peer was not found in our lists. Add it. */
961964
peer_id = m_connection->createPeer(sender, MTP_MINETEST_RELIABLE_UDP, 0);
962965
}
963966

0 commit comments

Comments
 (0)