Place limit on the amount of alias recursion allowed, to prevent cycles or otherwise excessive recursion

This commit is contained in:
Monster Iestyn 2018-11-10 13:08:26 +00:00
parent 4b8232d777
commit 2da335a1c4

View file

@ -63,6 +63,7 @@ CV_PossibleValue_t CV_Unsigned[] = {{0, "MIN"}, {999999999, "MAX"}, {0, NULL}};
CV_PossibleValue_t CV_Natural[] = {{1, "MIN"}, {999999999, "MAX"}, {0, NULL}}; CV_PossibleValue_t CV_Natural[] = {{1, "MIN"}, {999999999, "MAX"}, {0, NULL}};
#define COM_BUF_SIZE 8192 // command buffer size #define COM_BUF_SIZE 8192 // command buffer size
#define MAX_ALIAS_RECURSION 100 // max recursion allowed for aliases
static INT32 com_wait; // one command per frame (for cmd sequences) static INT32 com_wait; // one command per frame (for cmd sequences)
@ -485,6 +486,7 @@ static void COM_ExecuteString(char *ptext)
{ {
xcommand_t *cmd; xcommand_t *cmd;
cmdalias_t *a; cmdalias_t *a;
static INT32 recursion = 0; // detects recursion and stops it if it goes too far
COM_TokenizeString(ptext); COM_TokenizeString(ptext);
@ -497,6 +499,7 @@ static void COM_ExecuteString(char *ptext)
{ {
if (!stricmp(com_argv[0], cmd->name)) //case insensitive now that we have lower and uppercase! if (!stricmp(com_argv[0], cmd->name)) //case insensitive now that we have lower and uppercase!
{ {
recursion = 0;
cmd->function(); cmd->function();
return; return;
} }
@ -507,11 +510,20 @@ static void COM_ExecuteString(char *ptext)
{ {
if (!stricmp(com_argv[0], a->name)) if (!stricmp(com_argv[0], a->name))
{ {
if (recursion > MAX_ALIAS_RECURSION)
{
CONS_Alert(CONS_WARNING, M_GetText("Alias recursion cycle detected!\n"));
recursion = 0;
return;
}
recursion++;
COM_BufInsertText(a->value); COM_BufInsertText(a->value);
return; return;
} }
} }
recursion = 0;
// check cvars // check cvars
// Hurdler: added at Ebola's request ;) // Hurdler: added at Ebola's request ;)
// (don't flood the console in software mode with bad gr_xxx command) // (don't flood the console in software mode with bad gr_xxx command)