Regular expressions does not crash anymore #489
Closed
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.
This PR fixes two bugs in regexps, but more importantly, it prevents regexp errors from always ending up in a core dump.
b2::regex::compiler::regcompb2::regex::program::result_iterator::advanceb2::regex::framevariable for formatting errors when using regexps (especially compilation) and program termination (optional).Be careful, now that b2 no longer core dumps when regexps contain errors, you have to consider that the errors could (and certainly will) go undetected.
Since these are rather subtle errors, it's not a good idea to ignore them. For this reason, the default
MATCHnow terminates execution with a nice error message, similar to the one emitted when the arguments are incorrect, in the case of problems compiling the regexps.This is actually implemented with a thread_local variable in the b2::regex namespace and a
frame_ctxhelper class, which is certainly not the cleanest way to do it but currently allows you to customize the error behavior with a minimal impact.A
grep 'regex::program' *in the sources allows you to quickly find where you are using regexps and you may want to force error checking, for example in the constructor ofregex_grep_task(although you need to know theFrame*).b2::regex::program::result_iterator::operator[]bug on boundary check fixedb2::regex::program::result_iterator::countmethod, for better regex usabilityabs_workdir.pytestWith these changes, MATCH not only no longer crashes on every error in a regex, but it also reports a detailed error to the user and stops execution. Example #488
now behaves like this:
This partially fixes #488, but it isn't all.
René, as far as I'm concerned, you can close this PR, since I'll need some time to check all the regexes out there and write a test that has good coverage.