Skip to content

Commit 193ab49

Browse files
authored
Properly handle invalid cvar replications without blocking netmessage (#408)
Properly handle invalid cvar replications without blocking netmessage entirely and restore `ns_server_name` replication
1 parent fc087d8 commit 193ab49

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

primedev/server/serverpresence.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void ServerPresenceManager::CreateConVars()
7878
Cvar_ns_server_presence_update_rate = new ConVar(
7979
"ns_server_presence_update_rate", "5000", FCVAR_GAMEDLL, "How often we update our server's presence on server lists in ms");
8080

81-
Cvar_ns_server_name = new ConVar("ns_server_name", "Unnamed Northstar Server", FCVAR_GAMEDLL, "This server's name", false, 0, false, 0, [](ConVar* cvar, const char* pOldValue, float flOldValue) {
81+
Cvar_ns_server_name = new ConVar("ns_server_name", "Unnamed Northstar Server", FCVAR_GAMEDLL | FCVAR_REPLICATED, "This server's name", false, 0, false, 0, [](ConVar* cvar, const char* pOldValue, float flOldValue) {
8282
NOTE_UNUSED(cvar);
8383
NOTE_UNUSED(pOldValue);
8484
NOTE_UNUSED(flOldValue);
@@ -88,7 +88,7 @@ void ServerPresenceManager::CreateConVars()
8888
Cvar_hostname->SetValue(g_pServerPresence->Cvar_ns_server_name->GetString());
8989
});
9090

91-
Cvar_ns_server_desc = new ConVar("ns_server_desc", "Default server description", FCVAR_GAMEDLL, "This server's description", false, 0, false, 0, [](ConVar* cvar, const char* pOldValue, float flOldValue) {
91+
Cvar_ns_server_desc = new ConVar("ns_server_desc", "Default server description", FCVAR_GAMEDLL | FCVAR_REPLICATED, "This server's description", false, 0, false, 0, [](ConVar* cvar, const char* pOldValue, float flOldValue) {
9292
NOTE_UNUSED(cvar);
9393
NOTE_UNUSED(pOldValue);
9494
NOTE_UNUSED(flOldValue);

primedev/shared/exploit_fixes/exploitfixes.cpp

+24-12
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,31 @@ bool, __fastcall, (void* pMsg)) // 48 8B D1 48 8B 49 18 48 8B 01 48 FF 60 10
120120
if (!nameValid || !valValid)
121121
return BLOCKED_INFO("Missing null terminators");
122122

123-
ConVar* pVar = g_pCVar->FindVar(entry->name);
124-
125-
if (pVar)
123+
// we only need to check if these cvars are valid on client as it will set actual cvars there
124+
// on server this won't set any actual convars, only keyvalues in the player, which doesn't have really any potential for dumb
125+
// stuff
126+
if (!bIsServerFrame)
126127
{
127-
memcpy(
128-
entry->name,
129-
pVar->m_ConCommandBase.m_pszName,
130-
strlen(pVar->m_ConCommandBase.m_pszName) + 1); // Force name to match case
131-
132-
int iFlags = bIsServerFrame ? FCVAR_USERINFO : FCVAR_REPLICATED;
133-
if (!pVar->IsFlagSet(iFlags))
134-
return BLOCKED_INFO(
135-
"Invalid flags (" << std::hex << "0x" << pVar->m_ConCommandBase.m_nFlags << "), var is " << entry->name);
128+
ConVar* pVar = g_pCVar->FindVar(entry->name);
129+
if (pVar)
130+
{
131+
memcpy(
132+
entry->name,
133+
pVar->m_ConCommandBase.m_pszName,
134+
strlen(pVar->m_ConCommandBase.m_pszName) + 1); // Force name to match case
135+
136+
if (!pVar->IsFlagSet(FCVAR_REPLICATED))
137+
{
138+
spdlog::warn(
139+
"Blocking replication of remote cvar {} from server (server's var has flag REPLICATED, while ours does not)",
140+
entry->name);
141+
142+
// don't block, as non-malicious servers might send bad cvars, and we still want those clients to be able to
143+
// connect
144+
memset(entry->name, 0, ENTRY_STR_LEN);
145+
memset(entry->val, 0, ENTRY_STR_LEN);
146+
}
147+
}
136148
}
137149
}
138150
else

0 commit comments

Comments
 (0)