Lock down MessageBox handler

This commit is contained in:
Boondorl 2025-07-28 12:56:56 -04:00 committed by Ricardo Luís Vaz Silva
commit 4acc5f2a7d
3 changed files with 12 additions and 9 deletions

View file

@ -278,6 +278,8 @@ xx(OptionMenuItemColorPicker)
xx(OptionMenuItemStaticText)
xx(OptionMenuItemStaticTextSwitchable)
xx(Handler)
xx(Color)
xx(Mididevices)

View file

@ -47,9 +47,10 @@ CVAR(Bool, m_quickexit, false, CVAR_ARCHIVE)
typedef void(*hfunc)();
DEFINE_ACTION_FUNCTION(DMessageBoxMenu, CallHandler)
{
PARAM_PROLOGUE;
PARAM_POINTERTYPE(Handler, hfunc);
Handler();
PARAM_SELF_PROLOGUE(DMenu);
auto handler = reinterpret_cast<hfunc>(self->PointerVar<void>(NAME_Handler));
if (handler != nullptr)
handler();
return 0;
}
@ -68,7 +69,8 @@ DMenu *CreateMessageBoxMenu(DMenu *parent, const char *message, int messagemode,
IFVIRTUALPTRNAME(p, NAME_MessageBoxMenu, Init)
{
VMValue params[] = { p, parent, &namestr, messagemode, playsound, action.GetIndex(), reinterpret_cast<void*>(handler) };
p->PointerVar<void>(NAME_Handler) = reinterpret_cast<void*>(handler);
VMValue params[] = { p, parent, &namestr, messagemode, playsound, action.GetIndex() };
VMCall(func, params, countof(params), nullptr, 0);
return (DMenu*)p;
}

View file

@ -35,7 +35,7 @@
class MessageBoxMenu : Menu
{
BrokenLines mMessage;
readonly internal voidptr Handler;
readonly voidptr Handler;
int mMessageMode;
int messageSelection;
int mMouseLeft, mMouseRight, mMouseY;
@ -45,7 +45,7 @@ class MessageBoxMenu : Menu
int destWidth, destHeight;
String selector;
private native static void CallHandler(voidptr hnd);
native void CallHandler();
//=============================================================================
@ -54,7 +54,7 @@ class MessageBoxMenu : Menu
//
//=============================================================================
virtual void Init(Menu parent, String message, int messagemode, bool playsound = false, Name cmd = 'None', voidptr native_handler = null)
virtual void Init(Menu parent, String message, int messagemode, bool playsound = false, Name cmd = 'None')
{
Super.Init(parent);
mAction = cmd;
@ -95,7 +95,6 @@ class MessageBoxMenu : Menu
{
MenuSound ("menu/prompt");
}
Handler = native_handler;
}
//=============================================================================
@ -164,7 +163,7 @@ class MessageBoxMenu : Menu
{
if (res)
{
CallHandler(Handler);
CallHandler();
}
else
{