diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-10-18 18:06:54 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-10-18 18:09:21 +0200 |
commit | 898a28de86600b62ddd5f971b910eaadc222bbb7 (patch) | |
tree | 7d4e18f136e50517f154c372f057937f1992ee77 /eval.c | |
parent | d815d0e0ee00de41e792246ba1baddf1d68b0f59 (diff) |
ast, eval: add recursion limit
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -981,12 +981,16 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this, op = ut_get_op(state, off); + if (state->calldepth >= 1000) + return ut_new_exception(state, op->off, "Runtime error: Too much recursion"); + callstack.next = state->callstack; callstack.source = state->source; callstack.funcname = state->function ? state->function->name : NULL; callstack.off = op ? op->off : 0; callstack.ctx = json_object_get(this ? this : state->ctx); state->callstack = &callstack; + state->calldepth++; /* is native function */ if (tag->type == T_CFUNC) { @@ -1042,6 +1046,7 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this, json_object_put(callstack.ctx); state->callstack = callstack.next; + state->calldepth--; return rv; } |