Skip to content

Commit

Permalink
Added stack pointer validation for call function/method opcodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Nov 24, 2024
1 parent de687b2 commit 66600dc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cleo_plugins/MemoryOperations/MemoryOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ class MemoryOperations
SCRIPT_VAR* arguments_end = arguments + numArg;
numPop *= 4; // bytes peer argument
DWORD result;
int oriSp, postSp; // stack validation
_asm
{
mov oriSp, esp

// transfer args to stack
lea ecx, arguments
call_func_loop :
Expand All @@ -179,6 +182,21 @@ class MemoryOperations
call func
mov result, eax // get result
add esp, numPop // cleanup stack

mov postSp, esp
}

// validate stack pointer
if (postSp != oriSp)
{
_asm
{
mov esp, oriSp // fix stack pointer
}

int diff = oriSp - postSp;
SHOW_ERROR("Function call left stack position changed (%s%d) in script %s \nScript suspended.", diff > 0 ? "+" : "", diff, CLEO::ScriptInfoStr(thread).c_str());
return thread->Suspend();
}

if (returnArg)
Expand Down

0 comments on commit 66600dc

Please sign in to comment.