Skip to content

Commit f90c3d5

Browse files
fix(enterchat): fixing statstring buffer overwrite of product
1 parent 47cb2e9 commit f90c3d5

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

src/Atlasd/Battlenet/Protocols/Game/Messages/SID_ENTERCHAT.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Atlasd.Battlenet.Exceptions;
22
using Atlasd.Daemon;
33
using System;
4+
using System.Linq;
45
using System.Collections.Generic;
56
using System.IO;
67
using System.Text;
@@ -51,17 +52,10 @@ public override bool Invoke(MessageContext context)
5152

5253
var productId = (UInt32)gameState.Product;
5354

54-
// Statstring length is either 0 bytes or 4-128 bytes, not including the null-terminator.
55-
if (statstring.Length != 0 && (statstring.Length < 4 || statstring.Length > 128))
55+
// Statstring has a maximum length of 128 bytes
56+
if (statstring.Length > 128)
5657
throw new GameProtocolViolationException(context.Client, $"Client sent invalid statstring size in {MessageName(Id)}");
5758

58-
if (statstring.Length < 4) statstring = new byte[4];
59-
60-
using var _m = new MemoryStream(statstring);
61-
using var _w = new BinaryWriter(_m);
62-
_w.BaseStream.Position = 0;
63-
_w.Write(productId); // ensure first 4 bytes of statstring always matches their agreed upon productId
64-
6559
return new SID_ENTERCHAT().Invoke(new MessageContext(context.Client, MessageDirection.ServerToClient,
6660
new Dictionary<string, dynamic>(){{ "username", username }, { "statstring", statstring }})
6761
);
@@ -74,7 +68,7 @@ public override bool Invoke(MessageContext context)
7468

7569
// Do not use client-provided statstring if config.battlenet.emulation.statstring_updates is not enabled for this product.
7670
// Blizzard servers allowed statstring updates for Diablo, Diablo II (changing characters), Warcraft III (changing icons), and Shareware variants.
77-
if (!GameState.CanStatstringUpdate(gameState.Product)) statstring = gameState.GenerateStatstring();
71+
if (!GameState.CanStatstringUpdate(gameState.Product) || statstring.Length == 0) statstring = gameState.GenerateStatstring();
7872

7973
/**
8074
* (STRING) Unique name

0 commit comments

Comments
 (0)