alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
990 stars 425 forks source link

ClientPrefs cookie creation racing clients #726

Open InvexByte opened 7 years ago

InvexByte commented 7 years ago

For context and information on the issue please read: https://forums.alliedmods.net/showthread.php?t=296658


Summary


Replicating the Bug


This may or may not be a SM bug. May just be a plugin bug. However, it does seem that SM allows the clientprefs database to reach an invalid state (with entries in sm_cookies_cache containing duplicate rows with an invalid non-existent cookie_id).

Comments by psychonic and asherkin in IRC:

<psychonic> Byte, file an Issue
<psychonic> Blind guess at the bug is issue with detecting hltv in core after map change combined with validation bug in cp
<psychonic> Haven’t been able to dig into it yet. Could have been triggered by a change in the engine
<asherkin> I don't see how a client could have anything to do with the cookie id getting corrupted
<asherkin> I think it is more because of timing when it is joining
<asherkin> there are definitely races with cookie loading, the code is a mess

Any help/ideas to test are appreciated.

KyleSanderson commented 6 years ago

Whoa, yeah; RegClientCookie is typically only called at plugin startup, with clients joining afterwards. GoTV already being present, and calling this afterwards is as just asking for trouble. I'm sure you've noticed that multi1v1_autospec and multi1v1_hidestats are fine, because they're not hidden away.

At one point, this seemed a little more familiar to everything else. https://github.com/splewis/csgo-multi-1v1/blob/2710defb25f7f628cb6c950379325b54ed55d120/scripting/multi1v1/generic.sp#L96 cookies were already generated, and created via https://github.com/splewis/csgo-multi-1v1/blob/2710defb25f7f628cb6c950379325b54ed55d120/scripting/multi1v1.sp#L160

Was splewis wrong for doing this? no. Reverting back to that known pattern that was there would fix this, or if he calls CloseHandle(FindNamedCookie("cookies")) in OnPluginStart that would almost certainly paper over this.