Skip to content

Commit

Permalink
Made unsafe execution context check for CVARs more strict
Browse files Browse the repository at this point in the history
This prevents changing of non-mod CVARs from unsafe context for various code paths including set and toggle CCMDs
  • Loading branch information
alexey-lysiuk committed Jan 29, 2018
1 parent c7eea9b commit 1e9fdca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/c_cvars.cpp
Expand Up @@ -53,6 +53,7 @@
#include "colormatcher.h"
#include "menu/menu.h"
#include "vm.h"
#include "v_text.h"

struct FLatchedValue
{
Expand Down Expand Up @@ -156,6 +157,11 @@ void FBaseCVar::SetGenericRep (UCVarValue value, ECVarType type)
{
return;
}
else if (UnsafeExecutionContext && !(GetFlags() & CVAR_MOD))
{
Printf(TEXTCOLOR_RED "Cannot set console variable" TEXTCOLOR_GOLD " %s " TEXTCOLOR_RED "from unsafe command\n", GetName());
return;
}
else if ((Flags & CVAR_LATCH) && gamestate != GS_FULLCONSOLE && gamestate != GS_STARTUP)
{
FLatchedValue latch;
Expand Down
9 changes: 1 addition & 8 deletions src/c_dispatch.cpp
Expand Up @@ -127,8 +127,7 @@ FButtonStatus Button_Mlook, Button_Klook, Button_Use, Button_AltAttack,
Button_AM_PanLeft, Button_AM_PanRight, Button_AM_PanDown, Button_AM_PanUp,
Button_AM_ZoomIn, Button_AM_ZoomOut;

bool ParsingKeyConf;
static bool UnsafeExecutionContext;
bool ParsingKeyConf, UnsafeExecutionContext;

// To add new actions, go to the console and type "key <action name>".
// This will give you the key value to use in the first column. Then
Expand Down Expand Up @@ -658,12 +657,6 @@ void C_DoCommand (const char *cmd, int keynum)

if (args.argc() >= 2)
{ // Set the variable
if (UnsafeExecutionContext && !(var->GetFlags() & CVAR_MOD))
{
Printf(TEXTCOLOR_RED "Cannot set console variable" TEXTCOLOR_GOLD " %s " TEXTCOLOR_RED "from unsafe command\n", var->GetName());
return;
}

var->CmdSet (args[1]);
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/c_dispatch.h
Expand Up @@ -200,7 +200,7 @@ extern FButtonStatus Button_Mlook, Button_Klook, Button_Use, Button_AltAttack,
Button_User1, Button_User2, Button_User3, Button_User4,
Button_AM_PanLeft, Button_AM_PanRight, Button_AM_PanDown, Button_AM_PanUp,
Button_AM_ZoomIn, Button_AM_ZoomOut;
extern bool ParsingKeyConf;
extern bool ParsingKeyConf, UnsafeExecutionContext;

void ResetButtonTriggers (); // Call ResetTriggers for all buttons
void ResetButtonStates (); // Same as above, but also clear bDown
Expand Down

0 comments on commit 1e9fdca

Please sign in to comment.