Skip to content

Commit aa3a0fa

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 aa3a0fa

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

engine/server/sv_client.c

+30-16
Original file line numberDiff line numberDiff line change
@@ -852,39 +852,53 @@ 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+
int remaining;
872+
char temp[sizeof( s )];
873+
qboolean have_password = COM_CheckStringEmpty( sv_password.string );
871874

872875
SV_GetPlayerCount( &count, &bots );
873876

874877
// 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 );
878+
Info_SetValueForKey( s, "p", va( "%i", PROTOCOL_VERSION ), sizeof( s ));
879+
Info_SetValueForKey( s, "map", sv.name, sizeof( s ));
880+
Info_SetValueForKey( s, "dm", svgame.globals->deathmatch ? "1" : "0", sizeof( s ));
881+
Info_SetValueForKey( s, "team", svgame.globals->teamplay ? "1" : "0", sizeof( s ));
882+
Info_SetValueForKey( s, "coop", svgame.globals->coop ? "1" : "0", sizeof( s ));
883+
Info_SetValueForKey( s, "numcl", va( "%i", count ), sizeof( s ));
884+
Info_SetValueForKey( s, "maxcl", va( "%i", svs.maxclients ), sizeof( s ));
885+
Info_SetValueForKey( s, "gamedir", GI->gamefolder, sizeof( s ));
886+
Info_SetValueForKey( s, "password", have_password ? "1" : "0", sizeof( s ));
887+
888+
// write host last so we can try to cut off too long hostnames
889+
// TODO: value size limit for infostrings
890+
remaining = sizeof( s ) - Q_strlen( s ) - sizeof( "\\host\\" ) - 1;
891+
if( remaining < 0 )
892+
{
893+
// should never happen?
894+
Con_Printf( S_ERROR "SV_Info: infostring overflow!\n" );
895+
return;
896+
}
897+
Q_strncpy( temp, hostname.string, remaining );
898+
Info_SetValueForKey( s, "host", temp, sizeof( s ));
885899
}
886900

887-
Netchan_OutOfBandPrint( NS_SERVER, from, "info\n%s", string );
901+
Netchan_OutOfBandPrint( NS_SERVER, from, "info\n%s", s );
888902
}
889903

890904
/*

0 commit comments

Comments
 (0)