diff options
author | Andrey Nazarov <skuller@skuller.net> | 2007-10-07 20:09:00 +0000 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2007-10-07 20:09:00 +0000 |
commit | e2a278c4a223328ac8c90d8c2b8b7c86cf095fa1 (patch) | |
tree | 066598d97300032c7a6f88f4cf0b4d656adbe4b1 /source/q_shared.c | |
parent | 8c81e98c2ae39b84efda70df9eb30a6d8a7a45be (diff) |
Added sv_uptime cvar.
Optimized some string buffer functions.
Made redirect buffer size safe.
Diffstat (limited to 'source/q_shared.c')
-rw-r--r-- | source/q_shared.c | 92 |
1 files changed, 61 insertions, 31 deletions
diff --git a/source/q_shared.c b/source/q_shared.c index 48f7e1e..bb0df37 100644 --- a/source/q_shared.c +++ b/source/q_shared.c @@ -2097,42 +2097,53 @@ Info_SetValueForKey ================== */ void Info_SetValueForKey( char *s, const char *key, const char *value ) { - char newi[MAX_INFO_STRING], *v; - int c, l, newl; + char newi[MAX_INFO_STRING]; + int c, l, kl, vl; + const char *v; - if( strchr( key, '\\' ) || strchr( value, '\\' ) ) { - Com_Printf( "Can't use keys or values with a \\\n" ); - return; - } - - if( strchr( key, ';' ) ) { - Com_Printf( "Can't use keys or values with a semicolon\n" ); - return; + // validate key + v = key; + while( *v ) { + if( *v == '\\' || *v == '\"' || *v == ';' ) { + Com_Printf( "Can't use keys with backslashes, double quotes or semicolons\n" ); + return; + } + v++; } + kl = v - key; + if( kl >= MAX_INFO_KEY ) { + Com_Printf( "Keys must be less then %d characters.\n", MAX_INFO_KEY ); + return; + } - if( strchr( key, '\"' ) || strchr( value, '\"' ) ) { - Com_Printf ("Can't use keys or values with a \"\n"); - return; + // validate value + v = value; + while( *v ) { + if( *v == '\\' || *v == '\"' || *v == ';' ) { + Com_Printf( "Can't use values with backslashes, double quotes or semicolons\n" ); + return; + } + v++; } + vl = v - value; + if( kl >= MAX_INFO_VALUE ) { + Com_Printf( "Values must be less then %d characters.\n", MAX_INFO_VALUE ); + return; + } - if( strlen( key ) > MAX_INFO_KEY - 1 || strlen( value ) > MAX_INFO_VALUE - 1 ) { - Com_Printf( "Keys and values must be less then %i characters.\n", MAX_INFO_KEY ); - return; - } Info_RemoveKey( s, key ); if( !value[0] ) { return; } l = strlen( s ); - - newl = Com_sprintf( newi, sizeof( newi ), "\\%s\\%s", key, value ); - - if( newl + l > MAX_INFO_STRING - 1 ) { + if( l + kl + vl + 2 >= MAX_INFO_STRING ) { Com_Printf( "Info string length exceeded\n" ); return; } + sprintf( newi, "\\%s\\%s", key, value ); + // only copy ascii values s += l; v = newi; @@ -2151,15 +2162,35 @@ Info_AttemptSetValueForKey ================== */ qboolean Info_AttemptSetValueForKey( char *s, const char *key, const char *value ) { - char newi[MAX_INFO_STRING], *v; - int c, l, newl; + char newi[MAX_INFO_STRING]; + int c, l, kl, vl; + const char *v; - if( !Info_ValidateSubstring( key ) ) { - return qfalse; + // validate key + v = key; + while( *v ) { + if( *v == '\\' || *v == '\"' || *v == ';' ) { + return qfalse; + } + v++; } - if( !Info_ValidateSubstring( value ) ) { - return qfalse; + kl = v - key; + if( kl >= MAX_INFO_KEY ) { + return qfalse; + } + + // validate value + v = value; + while( *v ) { + if( *v == '\\' || *v == '\"' || *v == ';' ) { + return qfalse; + } + v++; } + vl = v - value; + if( vl >= MAX_INFO_KEY ) { + return qfalse; + } Info_RemoveKey( s, key ); if( !value[0] ) { @@ -2167,13 +2198,12 @@ qboolean Info_AttemptSetValueForKey( char *s, const char *key, const char *value } l = strlen( s ); - - newl = Com_sprintf( newi, sizeof( newi ), "\\%s\\%s", key, value ); - - if( newl + l > MAX_INFO_STRING - 1 ) { + if( l + kl + vl + 2 >= MAX_INFO_STRING ) { return qfalse; } + sprintf( newi, "\\%s\\%s", key, value ); + // only copy ascii values s += l; v = newi; |