From 57a27eb9487a94e0e67daa3271ec1a997b307a71 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 14 Jul 2013 16:58:10 +1200 Subject: [PATCH] Restore packet size restriction with 128k limit. --- OpenRA.Game/Server/Connection.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Server/Connection.cs b/OpenRA.Game/Server/Connection.cs index 76799ee660..79b3d88a7a 100644 --- a/OpenRA.Game/Server/Connection.cs +++ b/OpenRA.Game/Server/Connection.cs @@ -25,6 +25,7 @@ namespace OpenRA.Server public int ExpectLength = 8; public int Frame = 0; public int MostRecentFrame = 0; + public const int MaxOrderLength = 131072; /* client data */ public int PlayerIndex; @@ -65,7 +66,7 @@ namespace OpenRA.Server if (e.SocketErrorCode == SocketError.WouldBlock) break; server.DropClient(this); - Log.Write("server", "Dropping client {0} because reading the data failed: {1}", this.PlayerIndex.ToString(), e); + Log.Write("server", "Dropping client {0} because reading the data failed: {1}", PlayerIndex, e); return false; } } @@ -86,6 +87,13 @@ namespace OpenRA.Server ExpectLength = BitConverter.ToInt32(bytes, 0) - 4; Frame = BitConverter.ToInt32(bytes, 4); State = ReceiveState.Data; + + if (ExpectLength < 0 || ExpectLength > MaxOrderLength) + { + server.DropClient(this); + Log.Write("server", "Dropping client {0} for excessive order length = {1}", PlayerIndex, ExpectLength); + return; + } } break; case ReceiveState.Data: