Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix cg.skulltrails out of bounds access in Team Arena Harvester mode
In Team Arena's Harvester mode, players corrupt your memory from beyond the grave. Gib the players to stop the corruption! CG_PlayerTokens is called for player entities, including corpses. The entity number is used for the index in cg.skulltrails which only has MAX_CLIENTS elements. This results in incorrect memory being overwritten for corpse entities (as the entity number is >= MAX_CLIENTS). So limit skull trails to valid entities (entity number < MAX_CLIENTS).
- Loading branch information
b9061c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be safer to check;
The array length is
MAX_CLIENTS
, but this way you could change it without breaking the check. Furthermore I find it makes it more obvious that we're checking the bounds ofskulltrails[]
instead of usingMAX_CLIENTS
out of nowhere.b9061c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about using ARRAY_LEN but it didn't seem like it fit the existing code style. I think this is how it would of been fixed 14 years ago if it had been found. ARRAY_LEN is generally used for arrays that the compiler determines the size based on initialized elements.
b9061c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably makes more sense to make a define for max skull trails that redefines value of max clients then ?
b9061c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't really argue against that, but maybe we can improve things a little now?
cg_t
'sskulltrails[MAX_CLIENTS]
can be used withARRAY_LEN
if I didn't miss something.I don't quite see what a
#define MAX_CLIENT_SKULLTRAILS MAX_CLIENTS
(MAX_SKULLTRAIL
is already defined, adding a plural s sounds too similar imho) would improve?Sure, you could compare
>= MAX_CLIENT_SKULLTRAILS
but you'd still need to look up howcg.skulltrails[]
is actually defined in order to understand the relation ofMAX_CLIENT_SKULLTRAILS
↔skulltrails[]
.I'm sorry for causing so much noise about such a little change 😅
b9061c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad robo :}