Skip to content

Commit

Permalink
Marked internal menu commands as safe
Browse files Browse the repository at this point in the history
This fixes soundfont/patchset/config selection menus in advanced sound options
  • Loading branch information
alexey-lysiuk committed Jan 30, 2018
1 parent c8b6e57 commit d9323b9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/c_dispatch.cpp
Expand Up @@ -692,7 +692,8 @@ DEFINE_ACTION_FUNCTION(DOptionMenuItemCommand, DoCommand)
if (CurrentMenu == nullptr) return 0;
PARAM_PROLOGUE;
PARAM_STRING(cmd);
UnsafeExecutionScope scope;
PARAM_BOOL(unsafe);
UnsafeExecutionScope scope(unsafe);
C_DoCommand(cmd);
return 0;
}
Expand Down
3 changes: 3 additions & 0 deletions src/menu/menu.cpp
Expand Up @@ -58,6 +58,7 @@
#include "vm.h"
#include "events.h"
#include "gl/renderer/gl_renderer.h" // for menu blur
#include "scripting/types.h"

//
// Todo: Move these elsewhere
Expand Down Expand Up @@ -1180,6 +1181,8 @@ DMenuItemBase * CreateOptionMenuItemCommand(const char *label, FName cmd, bool c
VMValue params[] = { p, &namestr, cmd.GetIndex(), centered };
auto f = dyn_cast<PFunction>(c->FindSymbol("Init", false));
VMCall(f->Variants[0].Implementation, params, countof(params), nullptr, 0);
auto unsafe = dyn_cast<PField>(c->FindSymbol("mUnsafe", false));
unsafe->Type->SetValue(reinterpret_cast<uint8_t*>(p) + unsafe->Offset, 0);
return (DMenuItemBase*)p;
}

Expand Down
6 changes: 4 additions & 2 deletions wadsrc/static/zscript/menu/optionmenuitems.txt
Expand Up @@ -128,16 +128,18 @@ class OptionMenuItemCommand : OptionMenuItemSubmenu
{
private String ccmd; // do not allow access to this from the outside.
bool mCloseOnSelect;
private bool mUnsafe;

OptionMenuItemCommand Init(String label, Name command, bool centered = false, bool closeonselect = false)
{
Super.Init(label, command, 0, centered);
ccmd = command;
mCloseOnSelect = closeonselect;
mUnsafe = true;
return self;
}

private native static void DoCommand(String cmd); // This is very intentionally limited to this menu item to prevent abuse.
private native static void DoCommand(String cmd, bool unsafe); // This is very intentionally limited to this menu item to prevent abuse.

override bool Activate()
{
Expand All @@ -151,7 +153,7 @@ class OptionMenuItemCommand : OptionMenuItemSubmenu
if (m.GetItem(mAction) != self) return false;
}
Menu.MenuSound("menu/choose");
DoCommand(ccmd);
DoCommand(ccmd, mUnsafe);
if (mCloseOnSelect)
{
let curmenu = Menu.GetCurrentMenu();
Expand Down

0 comments on commit d9323b9

Please sign in to comment.