Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow DUK_USE_EXEC_TIMEOUT_CHECK to be called from within the main loop of a long lived regular expression #2199

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ and agreed to irrevocably license their contributions under the Duktape
* Luis de Bethencourt (https://github.com/luisbg)
* Ian Whyman (https://github.com/v00d00)
* Rick Sayre (https://github.com/whorfin)
* Craig Edwards (https://github.com/braindigitalis)
* Craig Leres (https://github.com/leres)
* Maurici Abad (https://github.com/mauriciabad)
* Nancy Li (https://github.com/NancyLi1013)
Expand Down
16 changes: 16 additions & 0 deletions src-input/duk_regexp_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ DUK_LOCAL const duk_uint8_t *duk__match_regexp(duk_re_matcher_ctx *re_ctx, const
}
re_ctx->steps_count++;

#if defined(DUK_USE_EXEC_TIMEOUT_CHECK)
/* Ensure that timeouts still operate while parsing a regular expression.
* without this in place a large DUK_RE_EXECUTE_STEPS value will lock up the
* parser for many seconds, even if the user is trying to enforce a much lower
* time limit using an interrupt.
*/
if (DUK_USE_EXEC_TIMEOUT_CHECK(re_ctx->thr->heap->heap_udata)) {
DUK_D(DUK_DPRINT("execution timeout within regexp parsing, throwing a RangeError"));
re_ctx->thr->interrupt_init = 0;
re_ctx->thr->interrupt_counter = 0;
DUK_HEAP_CLEAR_INTERRUPT_RUNNING(re_ctx->thr->heap);
DUK_ERROR_RANGE(re_ctx->thr, "execution timeout");
DUK_WO_NORETURN(return NULL;);
}
#endif /* DUK_USE_EXEC_TIMEOUT_CHECK */

/* Opcodes are at most 7 bits now so they encode to one byte. If this
* were not the case or 'pc' is invalid here (due to a bug etc) we'll
* still fail safely through the switch default case.
Expand Down