8000 mint-arena: Add sanity checks for callvote arguments · Turtle-Arena/turtle-arena-code@4a2d786 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a2d786

Browse files
committed
mint-arena: Add sanity checks for callvote arguments
Don't allow callvote with text or empty string for int arguments. Don't allow negative or huge values for int arguments. Make 'callvote map' check if map exists.
1 parent b2efe17 commit 4a2d786

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

code/game/g_cmds.c

+64
Original file line numberDiff line numberDiff line change
@@ -1361,11 +1361,14 @@ void Cmd_Where_f( gentity_t *ent ) {
13611361
Cmd_CallVote_f
13621362
==================
13631363
*/
1364+
#define CALLVOTE_ARG2_NONE 1
1365+
#define CALLVOTE_ARG2_INTREGAL 2
13641366
void Cmd_CallVote_f( gentity_t *ent ) {
13651367
char* c;
13661368
int i;
13671369
char arg1[MAX_STRING_TOKENS];
13681370
char arg2[MAX_STRING_TOKENS];
1371+
int arg2Flags, arg2RangeMin, arg2RangeMax;
13691372

13701373
if ( !g_allowVote.integer ) {
13711374
trap_SendServerCommand( ent-g_entities, "print \"Voting not allowed here.\n\"" );
@@ -1401,23 +1404,73 @@ void Cmd_CallVote_f( gentity_t *ent ) {
14011404
}
14021405
}
14031406

1407+
arg2Flags = 0;
1408+
arg2RangeMin = 0;
1409+
arg2RangeMax = INT_MAX;
1410+
14041411
if ( !Q_stricmp( arg1, "map_restart" ) ) {
1412+
arg2Flags = CALLVOTE_ARG2_INTREGAL;
1413+
arg2RangeMax = 60; // max 1 minute
1414+
1415+
// default to 5 seconds if no argument was specified
1416+
if ( !arg2[0] ) {
1417+
Q_strncpyz( arg2, "5", sizeof( arg2 ) );
1418+
}
14051419
} else if ( !Q_stricmp( arg1, "nextmap" ) ) {
1420+
arg2Flags = CALLVOTE_ARG2_NONE;
14061421
} else if ( !Q_stricmp( arg1, "map" ) ) {
1422+
// string
14071423
} else if ( !Q_stricmp( arg1, "g_gametype" ) ) {
1424+
arg2Flags = CALLVOTE_ARG2_INTREGAL;
1425+
arg2RangeMax = GT_MAX_GAME_TYPE - 1;
14081426
} else if ( !Q_stricmp( arg1, "kick" ) ) {
1427+
// string
14091428
} else if ( !Q_stricmp( arg1, "kicknum" ) ) {
1429+
arg2Flags = CALLVOTE_ARG2_INTREGAL;
1430+
arg2RangeMax = MAX_CLIENTS;
14101431
} else if ( !Q_stricmp( arg1, "g_doWarmup" ) ) {
1432+
arg2Flags = CALLVOTE_ARG2_INTREGAL;
1433+
arg2RangeMax = 1;
14111434
} else if ( !Q_stricmp( arg1, "timelimit" ) ) {
1435+
arg2Flags = CALLVOTE_ARG2_INTREGAL;
1436+
arg2RangeMax = 240; // 4 hours
14121437
} else if ( !Q_stricmp( arg1, "fraglimit" ) ) {
1438+
arg2Flags = CALLVOTE_ARG2_INTREGAL;
1439+
arg2RangeMax = 999;
14131440
} else if ( !Q_stricmp( arg1, "capturelimit" ) ) {
1441+
arg2Flags = CALLVOTE_ARG2_INTREGAL;
1442+
arg2RangeMax = 999;
14141443
} else if ( !Q_stricmp( arg1, "g_instagib" ) ) {
1444+
arg2Flags = CALLVOTE_ARG2_INTREGAL;
1445+
arg2RangeMax = 1;
14151446
} else {
14161447
trap_SendServerCommand( ent-g_entities, "print \"Invalid vote string.\n\"" );
14171448
trap_SendServerCommand( ent-g_entities, "print \"Vote commands are: map_restart, nextmap, map <mapname>, g_gametype <n>, kick <player>, kicknum <playernum>, g_doWarmup <boolean>, timelimit <time>, fraglimit <frags>, capturelimit <captures>, g_instagib <boolean>.\n\"" );
14181449
return;
14191450
}
14201451

1452+
if ( ( arg2Flags & CALLVOTE_ARG2_NONE ) && arg2[0] != '\0' ) {
1453+
trap_SendServerCommand( ent-g_entities, va( "print \"Vote command %s does not accept an argument.\n\"", arg1 ) );
1454+
return;
1455+
}
1456+
else if ( arg2[0] == '\0' ) {
1457+
trap_SendServerCommand( ent-g_entities, va( "print \"Vote command %s requires an argument.\n\"", arg1 ) );
1458+
return;
1459+
}
1460+
1461+
if ( ( arg2Flags & CALLVOTE_ARG2_INTREGAL ) ) {
1462+
if ( !StringIsInteger( arg2 ) ) {
1463+
trap_SendServerCommand( ent-g_entities, va( "print \"Vote command %s argument must be a number.\n\"", arg1 ) );
1464+
return;
1465+
}
< 8000 /code>
1466+
1467+
i = atoi( arg2 );
1468+
if ( i < arg2RangeMin || i > arg2RangeMax ) {
1469+
trap_SendServerCommand( ent-g_entities, va( "print \"Vote command %s argument must be %d to %d.\n\"", arg1, arg2RangeMin, arg2RangeMax ) );
1470+
return;
1471+
}
1472+
}
1473+
14211474
// if there is still a vote to be executed
14221475
if ( level.voteExecuteTime ) {
14231476
// don't start a vote when map change or restart is in progress
@@ -1445,6 +1498,17 @@ void Cmd_CallVote_f( gentity_t *ent ) {
14451498
// special case for map changes, we want to reset the nextmap setting
14461499
// this allows a player to change maps, but not upset the map rotation
14471500
char s[MAX_STRING_CHARS];
1501+
char filename[MAX_QPATH];
1502+
1503+
if ( strstr( arg2, ".." ) || strstr( arg2, "::" ) || strlen( arg2 ) + 9 >= MAX_QPATH ) {
1504+
trap_SendServerCommand( ent-g_entities, "print \"Invalid map name.\n\"" );
1505+
return;
1506+
}
1507+
Com_sprintf( filename, sizeof( filename ), "maps/%s.bsp", arg2 );
1508+
if ( trap_FS_FOpenFile( filename, NULL, FS_READ ) <= 0 ) {
1509+
trap_SendServerCommand( ent-g_entities, "print \"Map not found.\n\"" );
1510+
return;
1511+
}
14481512

14491513
trap_Cvar_VariableStringBuffer( "nextmap", s, sizeof(s) );
14501514
if (*s) {

0 commit comments

Comments
 (0)
0