From d1abff28e40d86c34e93ddbf2af222ffe552f6b8 Mon Sep 17 00:00:00 2001 From: Christopher Schwarz Date: Fri, 16 Oct 2009 22:29:39 +0000 Subject: * (bug 4303) Disallow blank hostnames and non-printing characters in the server browser (thanks Khalsa) --- src/ui/ui_main.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/ui/ui_main.c b/src/ui/ui_main.c index c88363ce..15699991 100644 --- a/src/ui/ui_main.c +++ b/src/ui/ui_main.c @@ -265,6 +265,37 @@ void UI_DrawRect( float x, float y, float width, float height, float size, const trap_R_SetColor( NULL ); } +/* +================== +UI_ServerInfoIsValid + +Return false if the infostring contains nonprinting characters, + or if the hostname is blank/undefined +================== +*/ +static qboolean UI_ServerInfoIsValid( char *info ) +{ + char *c; + int len = 0; + + for( c = info; *c; c++ ) + { + if( !isprint( *c ) ) + return qfalse; + } + + for( c = Info_ValueForKey( info, "hostname" ); *c; c++ ) + { + if( isgraph( *c ) ) + len++; + } + + if( len ) + return qfalse; + else + return qtrue; +} + /* ================== UI_InsertServerIntoDisplayList @@ -272,15 +303,17 @@ UI_InsertServerIntoDisplayList */ static void UI_InsertServerIntoDisplayList( int num, int position ) { - int i; + int i; static char info[MAX_STRING_CHARS]; if( position < 0 || position > uiInfo.serverStatus.numDisplayServers ) return; - trap_LAN_GetServerInfo( ui_netSource.integer, num, info, MAX_STRING_CHARS ); + if( !UI_ServerInfoIsValid( info ) ) // don't list servers with invalid info + return; + uiInfo.serverStatus.numDisplayServers++; for( i = uiInfo.serverStatus.numDisplayServers; i > position; i-- ) @@ -968,7 +1001,8 @@ static void UI_StopServerRefresh( void ) if( count - uiInfo.serverStatus.numDisplayServers > 0 ) { - Com_Printf( "%d servers not listed due to packet loss or pings higher than %d\n", + Com_Printf( "%d servers not listed due to packet loss, invalid info," + " or pings higher than %d\n", count - uiInfo.serverStatus.numDisplayServers, ( int ) trap_Cvar_VariableValue( "cl_maxPing" ) ); } -- cgit