From c8483de74f6285f13143b300285e2a6a4e984bde Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 24 Nov 2000 20:36:37 +0000 Subject: [PATCH] fix the 0 byte udp packet DoS bug (for linux, anyway: mods from ProQuake applied for windows, but I can't test). In, linux, the problem was caused by nuq checking to see if there were any bytes to be read and if there were 0 bytes, just carying on without reading anything. It seems that the 0 byte packet was blocking the queue and so a 0 byte recvfrom is needed to make sure it gets removed. --- source/net_mp.c | 2 +- source/net_udp.c | 4 ++++ source/net_wins.c | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/source/net_mp.c b/source/net_mp.c index 85273f4..868e3a9 100644 --- a/source/net_mp.c +++ b/source/net_mp.c @@ -262,7 +262,7 @@ int MPATH_CheckNewConnections (void) if (net_acceptsocket == -1) return -1; - if (recvfrom (net_acceptsocket, buf, 4, MSG_PEEK, NULL, NULL) > 0) + if (recvfrom (net_acceptsocket, buf, 4, MSG_PEEK, NULL, NULL) >= 0) return net_acceptsocket; return -1; } diff --git a/source/net_udp.c b/source/net_udp.c index 86b04ee..e565ce4 100644 --- a/source/net_udp.c +++ b/source/net_udp.c @@ -248,6 +248,9 @@ int UDP_Connect (int socket, struct qsockaddr *addr) int UDP_CheckNewConnections (void) { unsigned long available; + struct sockaddr_in from; + socklen_t fromlen; + char buff[1]; if (net_acceptsocket == -1) return -1; @@ -256,6 +259,7 @@ int UDP_CheckNewConnections (void) Sys_Error ("UDP: ioctlsocket (FIONREAD) failed\n"); if (available) return net_acceptsocket; + recvfrom (net_acceptsocket, buff, 0, 0, &from, &fromlen); return -1; } diff --git a/source/net_wins.c b/source/net_wins.c index ecd249d..3e189df 100644 --- a/source/net_wins.c +++ b/source/net_wins.c @@ -393,7 +393,7 @@ int WINS_CheckNewConnections (void) if (net_acceptsocket == -1) return -1; - if (precvfrom (net_acceptsocket, buf, sizeof(buf), MSG_PEEK, NULL, NULL) > 0) + if (precvfrom (net_acceptsocket, buf, sizeof(buf), MSG_PEEK, NULL, NULL) >= 0) { return net_acceptsocket; }