Add recursion limit for VM (#2737)

This patch adds posibility to supervise the VM call stack to avoid aborts/crashes due to the recursion calls.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2019-02-01 15:32:26 +01:00
committed by László Langó
parent 5c1a4f18ea
commit 6b9c924d08
7 changed files with 86 additions and 7 deletions
+22
View File
@@ -42,6 +42,13 @@
* @{
*/
/*
* Check VM recursion depth limit
*/
#ifdef VM_RECURSION_LIMIT
JERRY_STATIC_ASSERT (VM_RECURSION_LIMIT > 0, vm_recursion_limit_must_be_greater_than_zero);
#endif /* VM_RECURSION_LIMIT */
/**
* Get the value of object[property].
*
@@ -3515,6 +3522,10 @@ vm_execute (vm_frame_ctx_t *frame_ctx_p, /**< frame context */
}
#endif /* JERRY_DEBUGGER */
#ifdef VM_RECURSION_LIMIT
JERRY_CONTEXT (vm_recursion_counter)++;
#endif /* VM_RECURSION_LIMIT */
JERRY_CONTEXT (vm_top_context_p) = frame_ctx_p->prev_context_p;
return completion_value;
}
@@ -3535,6 +3546,17 @@ vm_run (const ecma_compiled_code_t *bytecode_header_p, /**< byte-code data heade
const ecma_value_t *arg_list_p, /**< arguments list */
ecma_length_t arg_list_len) /**< length of arguments list */
{
#ifdef VM_RECURSION_LIMIT
if (JERRY_UNLIKELY (JERRY_CONTEXT (vm_recursion_counter) == 0))
{
return ecma_raise_range_error (ECMA_ERR_MSG ("VM recursion limit is exceeded."));
}
else
{
JERRY_CONTEXT (vm_recursion_counter)--;
}
#endif /* VM_RECURSION_LIMIT */
ecma_value_t *literal_p;
vm_frame_ctx_t frame_ctx;
uint32_t call_stack_size;