mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-04 15:45:25 +00:00
LibWasm: Make blocks that take arguments actually work
Previously we were ignoring the actual parameters and setting the arity to an incorrect value, which could cause crashes (or unexpected traps).
This commit is contained in:
committed by
Ali Mohammad Pur
parent
b5ca290605
commit
fecbf0e03a
@@ -2424,11 +2424,14 @@ VALIDATE_INSTRUCTION(block)
|
||||
if (stack.size() < parameters.size())
|
||||
return Errors::invalid_stack_state();
|
||||
|
||||
for (size_t i = 0; i < parameters.size(); ++i) {
|
||||
for (size_t i = 1; i <= parameters.size(); ++i) {
|
||||
if (stack.take_last() != parameters[parameters.size() - i])
|
||||
return Errors::invalid_stack_state();
|
||||
}
|
||||
|
||||
for (auto& parameter : parameters)
|
||||
stack.append(parameter);
|
||||
|
||||
m_entered_scopes.append(ChildScopeKind::Block);
|
||||
m_block_details.empend(stack.actual_size(), Empty {});
|
||||
m_parent_contexts.append(m_context);
|
||||
@@ -2451,6 +2454,9 @@ VALIDATE_INSTRUCTION(loop)
|
||||
return Errors::invalid_stack_state();
|
||||
}
|
||||
|
||||
for (auto& parameter : parameters)
|
||||
stack.append(parameter);
|
||||
|
||||
m_entered_scopes.append(ChildScopeKind::Block);
|
||||
m_block_details.empend(stack.actual_size(), Empty {});
|
||||
m_parent_contexts.append(m_context);
|
||||
@@ -2476,6 +2482,9 @@ VALIDATE_INSTRUCTION(if_)
|
||||
return Errors::invalid_stack_state();
|
||||
}
|
||||
|
||||
for (auto& parameter : parameters)
|
||||
stack.append(parameter);
|
||||
|
||||
m_entered_scopes.append(args.else_ip.has_value() ? ChildScopeKind::IfWithElse : ChildScopeKind::IfWithoutElse);
|
||||
m_block_details.empend(stack.actual_size(), BlockDetails::IfDetails { stack, {} });
|
||||
m_parent_contexts.append(m_context);
|
||||
|
||||
Reference in New Issue
Block a user