From b98e6d5cc07ceffd0e1068ee1ba887b61eef3c8e Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Mon, 10 Mar 2014 15:54:52 -0500 Subject: [PATCH] Fix error handling in R_ParseSpawnVars When R_GetEntityToken returns qfalse it resets pointer for parsing, by R_ParseSpawnVars not returning qfalse it could cause an infinite loop. Also add newlines to printfs. --- code/renderergl2/tr_bsp.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/code/renderergl2/tr_bsp.c b/code/renderergl2/tr_bsp.c index d9fdb4ab..9402c4e5 100644 --- a/code/renderergl2/tr_bsp.c +++ b/code/renderergl2/tr_bsp.c @@ -2749,7 +2749,8 @@ qboolean R_ParseSpawnVars( char *spawnVarChars, int maxSpawnVarChars, int *numSp return qfalse; } if ( com_token[0] != '{' ) { - ri.Printf( PRINT_ALL, "R_ParseSpawnVars: found %s when expecting {",com_token ); + ri.Printf( PRINT_ALL, "R_ParseSpawnVars: found %s when expecting {\n",com_token ); + return qfalse; } // go through all the key / value pairs @@ -2758,7 +2759,8 @@ qboolean R_ParseSpawnVars( char *spawnVarChars, int maxSpawnVarChars, int *numSp // parse key if ( !R_GetEntityToken( keyname, sizeof( keyname ) ) ) { - ri.Printf( PRINT_ALL, "R_ParseSpawnVars: EOF without closing brace" ); + ri.Printf( PRINT_ALL, "R_ParseSpawnVars: EOF without closing brace\n" ); + return qfalse; } if ( keyname[0] == '}' ) { @@ -2767,18 +2769,18 @@ qboolean R_ParseSpawnVars( char *spawnVarChars, int maxSpawnVarChars, int *numSp // parse value if ( !R_GetEntityToken( com_token, sizeof( com_token ) ) ) { - ri.Printf( PRINT_ALL, "R_ParseSpawnVars: EOF without closing brace" ); - break; + ri.Printf( PRINT_ALL, "R_ParseSpawnVars: EOF without closing brace\n" ); + return qfalse; } if ( com_token[0] == '}' ) { - ri.Printf( PRINT_ALL, "R_ParseSpawnVars: closing brace without data" ); - break; + ri.Printf( PRINT_ALL, "R_ParseSpawnVars: closing brace without data\n" ); + return qfalse; } if ( *numSpawnVars == MAX_SPAWN_VARS ) { - ri.Printf( PRINT_ALL, "R_ParseSpawnVars: MAX_SPAWN_VARS" ); - break; + ri.Printf( PRINT_ALL, "R_ParseSpawnVars: MAX_SPAWN_VARS\n" ); + return qfalse; } keyLength = strlen(keyname) + 1; @@ -2786,8 +2788,8 @@ qboolean R_ParseSpawnVars( char *spawnVarChars, int maxSpawnVarChars, int *numSp if (numSpawnVarChars + keyLength + tokenLength > maxSpawnVarChars) { - ri.Printf( PRINT_ALL, "R_ParseSpawnVars: MAX_SPAWN_VAR_CHARS" ); - break; + ri.Printf( PRINT_ALL, "R_ParseSpawnVars: MAX_SPAWN_VAR_CHARS\n" ); + return qfalse; } strcpy(spawnVarChars + numSpawnVarChars, keyname);