Skip to content

Commit

Permalink
Add stack height verification to CALLF impl
Browse files Browse the repository at this point in the history
  • Loading branch information
rodiazet committed Mar 24, 2023
1 parent 3f6b1ed commit 8814293
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/evmone/instructions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,13 +933,21 @@ evmc_status_code create_impl(StackTop stack, ExecutionState& state) noexcept;
inline constexpr auto create = create_impl<OP_CREATE>;
inline constexpr auto create2 = create_impl<OP_CREATE2>;

inline code_iterator callf(StackTop /*stack*/, ExecutionState& state, code_iterator pos) noexcept
inline code_iterator callf(StackTop stack, ExecutionState& state, code_iterator pos) noexcept
{
const auto index = read_uint16_be(&pos[1]);

state.call_stack.push_back(pos + 3);

const auto& header = state.analysis.baseline->eof_header;

const auto stack_size = &stack.top() - state.stack_space.bottom();
if (stack_size + header.types[index].max_stack_height > StackSpace::limit)
{
state.status = EVMC_STACK_OVERFLOW;
return nullptr;
}

const auto offset = header.code_offsets[index] - header.code_offsets[0];
auto code = state.analysis.baseline->executable_code;
return code.data() + offset;
Expand Down

0 comments on commit 8814293

Please sign in to comment.