Allow DUK_USE_EXEC_TIMEOUT_CHECK to be called from within the main loop of a long lived regular expression #2199
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I am using duktape in an environment where it may be asked to run untrusted code as part of a platform as a service, and the function
duk__match_regexp()
can potentially run for a very long time if an abusive or broken regular expression is passed to it. This is somewhat mitigated by the value ofDUK_RE_EXECUTE_STEPS_LIMIT
, lowering this can solve the problem but it seems this cannot be lowered from duk_config.h, and i would have to edit my duktape.c to fix it.Based upon this i decided on this fix instead - i am already using
DUK_USE_EXEC_TIMEOUT_CHECK
with an interrupt function to prevent cpu consumption and various forms of resource abuse, but it seems the timeout function is not called from within theduk__match_regexp()
function.This PR adds support for calling the interrupt function from within the loop, this doesnt change any specification i'm aware of, as the docs say just that the interrupt function is 'called periodically' while running the script.
Please consider either merging this PR in some form, or allowing user configuration of
DUK_RE_EXECUTE_STEPS_LIMIT
andDUK_RE_COMPILE_TOKEN_LIMIT
.Thanks!