From 0f122fd5ddfd3e5512e44719c26ecfdc67f5aec7 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 30 Aug 2021 19:00:28 -0700 Subject: [PATCH] Don't accept hole punch requests to local network --- src/i_tcp.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 2a80022ef..f59bd083b 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -599,11 +599,37 @@ void Command_Numnodes(void) #endif #ifndef NONET +/* not one of the reserved "local" addresses */ +static boolean +is_external_address (UINT32 p) +{ + UINT8 a = (p & 255); + UINT8 b = ((p >> 8) & 255); + + if (p == (UINT32)~0)/* 255.255.255.255 */ + return 0; + + switch (a) + { + case 0: + case 10: + case 127: + return false; + case 172: + return (b & ~15) != 16;/* 16 - 31 */ + case 192: + return b != 168; + default: + return true; + } +} + static boolean hole_punch(ssize_t c) { /* See ../doc/Holepunch-Protocol.txt */ if (cv_rendezvousserver.string[0] && - c == 10 && holepunchpacket->magic == hole_punch_magic) + c == 10 && holepunchpacket->magic == hole_punch_magic && + is_external_address(ntohl(holepunchpacket->addr))) { mysockaddr_t addr; addr.ip4.sin_family = AF_INET;