From d9323b97404dcac48ac1b0226e23c69b8009afb6 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 30 Jan 2018 16:02:30 +0200 Subject: [PATCH] Marked internal menu commands as safe This fixes soundfont/patchset/config selection menus in advanced sound options --- src/c_dispatch.cpp | 3 ++- src/menu/menu.cpp | 3 +++ wadsrc/static/zscript/menu/optionmenuitems.txt | 6 ++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/c_dispatch.cpp b/src/c_dispatch.cpp index 358a6a5783..cb1fb47e1d 100644 --- a/src/c_dispatch.cpp +++ b/src/c_dispatch.cpp @@ -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; } diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 86ec78abf2..f03c37eb73 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -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 @@ -1180,6 +1181,8 @@ DMenuItemBase * CreateOptionMenuItemCommand(const char *label, FName cmd, bool c VMValue params[] = { p, &namestr, cmd.GetIndex(), centered }; auto f = dyn_cast(c->FindSymbol("Init", false)); VMCall(f->Variants[0].Implementation, params, countof(params), nullptr, 0); + auto unsafe = dyn_cast(c->FindSymbol("mUnsafe", false)); + unsafe->Type->SetValue(reinterpret_cast(p) + unsafe->Offset, 0); return (DMenuItemBase*)p; } diff --git a/wadsrc/static/zscript/menu/optionmenuitems.txt b/wadsrc/static/zscript/menu/optionmenuitems.txt index 4668ea0681..00fe4893cc 100644 --- a/wadsrc/static/zscript/menu/optionmenuitems.txt +++ b/wadsrc/static/zscript/menu/optionmenuitems.txt @@ -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() { @@ -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();