Skip to content

Commit 84c0de6

Browse files
committed
engine: server: increase infostring size in SV_Info allowing longer hostnames but try to cut off if it's even longer than that
1 parent c1287b3 commit 84c0de6

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

engine/server/sv_client.c

+29-16
Original file line numberDiff line numberDiff line change
@@ -852,39 +852,52 @@ The second parameter should be the current protocol version number.
852852
*/
853853
void SV_Info( netadr_t from, int protocolVersion )
854854
{
855-
char string[MAX_INFO_STRING];
855+
char s[512];
856856

857857
// ignore in single player
858858
if( svs.maxclients == 1 || !svs.initialized )
859859
return;
860860

861-
string[0] = '\0';
861+
s[0] = '\0';
862862

863863
if( protocolVersion != PROTOCOL_VERSION )
864864
{
865-
Q_snprintf( string, sizeof( string ), "%s: wrong version\n", hostname.string );
865+
Q_snprintf( s, sizeof( s ), "%s: wrong version\n", hostname.string );
866866
}
867867
else
868868
{
869-
int i, count, bots;
870-
qboolean havePassword = COM_CheckStringEmpty( sv_password.string );
869+
int count;
870+
int bots;
871+
char temp[sizeof( s )];
872+
qboolean have_password = COM_CheckStringEmpty( sv_password.string );
871873

872874
SV_GetPlayerCount( &count, &bots );
873875

874876
// a1ba: send protocol version to distinguish old engine and new
875-
Info_SetValueForKey( string, "p", va( "%i", PROTOCOL_VERSION ), MAX_INFO_STRING );
876-
Info_SetValueForKey( string, "host", hostname.string, MAX_INFO_STRING );
877-
Info_SetValueForKey( string, "map", sv.name, MAX_INFO_STRING );
878-
Info_SetValueForKey( string, "dm", va( "%i", (int)svgame.globals->deathmatch ), MAX_INFO_STRING );
879-
Info_SetValueForKey( string, "team", va( "%i", (int)svgame.globals->teamplay ), MAX_INFO_STRING );
880-
Info_SetValueForKey( string, "coop", va( "%i", (int)svgame.globals->coop ), MAX_INFO_STRING );
881-
Info_SetValueForKey( string, "numcl", va( "%i", count ), MAX_INFO_STRING );
882-
Info_SetValueForKey( string, "maxcl", va( "%i", svs.maxclients ), MAX_INFO_STRING );
883-
Info_SetValueForKey( string, "gamedir", GI->gamefolder, MAX_INFO_STRING );
884-
Info_SetValueForKey( string, "password", havePassword ? "1" : "0", MAX_INFO_STRING );
877+
Info_SetValueForKey( s, "p", va( "%i", PROTOCOL_VERSION ), sizeof( s ));
878+
Info_SetValueForKey( s, "map", sv.name, sizeof( s ));
879+
Info_SetValueForKey( s, "dm", svgame.globals->deathmatch ? "1" : "0", sizeof( s ));
880+
Info_SetValueForKey( s, "team", svgame.globals->teamplay ? "1" : "0", sizeof( s ));
881+
Info_SetValueForKey( s, "coop", svgame.globals->coop ? "1" : "0", sizeof( s ));
882+
Info_SetValueForKey( s, "numcl", va( "%i", count ), sizeof( s ));
883+
Info_SetValueForKey( s, "maxcl", va( "%i", svs.maxclients ), sizeof( s ));
884+
Info_SetValueForKey( s, "gamedir", GI->gamefolder, sizeof( s ));
885+
Info_SetValueForKey( s, "password", have_password ? "1" : "0", sizeof( s ));
886+
887+
// write host last so we can try to cut off too long hostnames
888+
// TODO: value size limit for infostrings
889+
remaining = sizeof( s ) - Q_strlen( s ) - sizeof( "\\host\\" ) - 1;
890+
if( remaining < 0 )
891+
{
892+
// should never happen?
893+
Con_Printf( S_ERROR "SV_Info: infostring overflow!\n" );
894+
return;
895+
}
896+
Q_strncpy( temp, hostname.string, remaining );
897+
Info_SetValueForKey( s, "host", temp, sizeof( s ));
885898
}
886899

887-
Netchan_OutOfBandPrint( NS_SERVER, from, "info\n%s", string );
900+
Netchan_OutOfBandPrint( NS_SERVER, from, "info\n%s", s );
888901
}
889902

890903
/*

0 commit comments

Comments
 (0)