mirror of
https://gitlab.com/Syroot/Worms.git
synced 2025-01-13 07:18:00 +03:00
Read packets more strictly to prevent crashes from bogus data.
This commit is contained in:
parent
48e6988083
commit
4c27eb415c
@ -11,6 +11,10 @@ namespace Syroot.Worms.Worms2.GameServer
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal class Packet
|
internal class Packet
|
||||||
{
|
{
|
||||||
|
// ---- CONSTANTS ----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
private const int _maxDataSize = 0x1000;
|
||||||
|
|
||||||
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
|
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -138,8 +142,8 @@ namespace Syroot.Worms.Worms2.GameServer
|
|||||||
internal void Receive(Stream stream)
|
internal void Receive(Stream stream)
|
||||||
{
|
{
|
||||||
int dataLength = 0;
|
int dataLength = 0;
|
||||||
Code = (PacketCode)stream.ReadInt32();
|
Code = stream.ReadEnum<PacketCode>(true);
|
||||||
Flags flags = (Flags)stream.ReadInt32();
|
Flags flags = stream.ReadEnum<Flags>(true);
|
||||||
if (flags.HasFlag(Flags.Value0)) Value0 = stream.ReadInt32();
|
if (flags.HasFlag(Flags.Value0)) Value0 = stream.ReadInt32();
|
||||||
if (flags.HasFlag(Flags.Value1)) Value1 = stream.ReadInt32();
|
if (flags.HasFlag(Flags.Value1)) Value1 = stream.ReadInt32();
|
||||||
if (flags.HasFlag(Flags.Value2)) Value2 = stream.ReadInt32();
|
if (flags.HasFlag(Flags.Value2)) Value2 = stream.ReadInt32();
|
||||||
@ -147,7 +151,8 @@ namespace Syroot.Worms.Worms2.GameServer
|
|||||||
if (flags.HasFlag(Flags.Value4)) Value4 = stream.ReadInt32();
|
if (flags.HasFlag(Flags.Value4)) Value4 = stream.ReadInt32();
|
||||||
if (flags.HasFlag(Flags.Value10)) Value10 = stream.ReadInt32();
|
if (flags.HasFlag(Flags.Value10)) Value10 = stream.ReadInt32();
|
||||||
if (flags.HasFlag(Flags.DataLength)) dataLength = stream.ReadInt32();
|
if (flags.HasFlag(Flags.DataLength)) dataLength = stream.ReadInt32();
|
||||||
if (flags.HasFlag(Flags.Data) && dataLength != 0) Data = stream.ReadFixedString(dataLength, Encodings.Windows1252);
|
if (flags.HasFlag(Flags.Data) && dataLength >= 0 && dataLength <= _maxDataSize)
|
||||||
|
Data = stream.ReadFixedString(dataLength, Encodings.Windows1252);
|
||||||
if (flags.HasFlag(Flags.Error)) Error = stream.ReadInt32();
|
if (flags.HasFlag(Flags.Error)) Error = stream.ReadInt32();
|
||||||
if (flags.HasFlag(Flags.Name)) Name = stream.ReadFixedString(20, Encodings.Windows1252);
|
if (flags.HasFlag(Flags.Name)) Name = stream.ReadFixedString(20, Encodings.Windows1252);
|
||||||
if (flags.HasFlag(Flags.Session)) Session = stream.ReadStruct<SessionInfo>();
|
if (flags.HasFlag(Flags.Session)) Session = stream.ReadStruct<SessionInfo>();
|
||||||
@ -159,8 +164,8 @@ namespace Syroot.Worms.Worms2.GameServer
|
|||||||
/// <param name="stream">The <see cref="Stream"/> to write the packet data to.</param>
|
/// <param name="stream">The <see cref="Stream"/> to write the packet data to.</param>
|
||||||
internal void Send(Stream stream)
|
internal void Send(Stream stream)
|
||||||
{
|
{
|
||||||
stream.WriteInt32((int)Code);
|
stream.WriteEnum(Code);
|
||||||
stream.WriteInt32((int)GetFlags());
|
stream.WriteEnum(GetFlags());
|
||||||
if (Value0.HasValue) stream.WriteInt32(Value0.Value);
|
if (Value0.HasValue) stream.WriteInt32(Value0.Value);
|
||||||
if (Value1.HasValue) stream.WriteInt32(Value1.Value);
|
if (Value1.HasValue) stream.WriteInt32(Value1.Value);
|
||||||
if (Value2.HasValue) stream.WriteInt32(Value2.Value);
|
if (Value2.HasValue) stream.WriteInt32(Value2.Value);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<Authors>Syroot</Authors>
|
<Authors>Syroot</Authors>
|
||||||
<Copyright>(c) Syroot, licensed under MIT</Copyright>
|
<Copyright>(c) Syroot, licensed under MIT</Copyright>
|
||||||
<Description>Worms 2 Game Server</Description>
|
<Description>Worms 2 Game Server</Description>
|
||||||
<Version>1.0.0</Version>
|
<Version>1.0.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<!-- References -->
|
<!-- References -->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user