From 71dcc1f8c6018dc2a4b3db8dfc9322e8e75211e3 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 2 Aug 2020 22:03:31 +1000 Subject: [PATCH 1/1] Don't attempt to network more than the maximum number of shown spectators, fixes a potential client crash --- qcsrc/client/main.qc | 9 ++++++++- qcsrc/server/client.qc | 4 ++++ qcsrc/server/client.qh | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 25403017b3..c2c9ee8a2f 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -474,12 +474,19 @@ NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew) for(i = 0; i < MAX_SPECTATORS; ++i) spectatorlist[i] = 0; // reset list first - for(i = 0; i < num_spectators; ++i) + int limit = min(num_spectators, MAX_SPECTATORS); + for(i = 0; i < limit; ++i) { slot = ReadByte(); spectatorlist[i] = slot - 1; } } + else + { + for(int j = 0; j < MAX_SPECTATORS; ++j) + spectatorlist[j] = 0; // reset list if showspectators has been turned off + num_spectators = 0; + } return = true; diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 3707c9e484..99aa86d24f 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -121,9 +121,13 @@ void WriteSpectators(entity player, entity to) { if(!player) { return; } // not sure how, but best to be safe + int spec_count = 0; FOREACH_CLIENT(IS_REAL_CLIENT(it) && IS_SPEC(it) && it != to && it.enemy == player, { + if(spec_count >= MAX_SPECTATORS) + break; WriteByte(MSG_ENTITY, num_for_edict(it)); + ++spec_count; }); } diff --git a/qcsrc/server/client.qh b/qcsrc/server/client.qh index e7c9036c73..8e5ee757f6 100644 --- a/qcsrc/server/client.qh +++ b/qcsrc/server/client.qh @@ -388,3 +388,5 @@ void Join(entity this); #define SPECTATE_COPYFIELD(fld) SPECTATE_COPY() { this.(fld) = spectatee.(fld); } int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodcontrol); + +const int MAX_SPECTATORS = 7; -- 2.39.2