-
Notifications
You must be signed in to change notification settings - Fork 199
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
Guard against out-of-bounds memory access when parsing LIMIT_HEAP et al #463
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Patterns passed to pcre2_compile are not guaranteed to be null-terminated. Also, it can happen that there is an invalid pattern like this: (*LIMIT_HEAP=123 If the next byte of memory after the end of the pattern happens to be a digit, it will be parsed as part of the limit value. Or, if the next byte is a right parenthesis character, it will be taken as the end of the (*LIMIT_HEAP=nnn) construct. This will result in `skipatstart` being larger than `patlen`, which will result in underflow and an erroneous call to malloc requesting a huge number of bytes.
alexdowad
commented
Sep 6, 2024
@@ -111,10 +111,10 @@ Minimum depth limit = 10 | |||
3: ee | |||
|
|||
/(*LIMIT_MATCH=12bc)abc/ | |||
Failed: error 160 at offset 17: (*VERB) not recognized or malformed | |||
Failed: error 160 at offset 16: (*VERB) not recognized or malformed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more logical now: the first bad character in the LIMIT_MATCH construct is at offset 16, not offset 17.
zherczeg
approved these changes
Sep 6, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
carenas
added a commit
to carenas/pcre2
that referenced
this pull request
Sep 21, 2024
As reported recently by ef218fb (Guard against out-of-bounds memory access when parsing LIMIT_HEAP et al (PCRE2Project#463), 2024-09-07), a malformed pattern could result in reading 1 byte past its end. Fix a similar issue that affects all VERBs and add test cases to ensure the original bug and all its siblings are no longer an issue. While at it fix the wording of the related documentation.
carenas
added a commit
to carenas/pcre2
that referenced
this pull request
Sep 22, 2024
As reported recently by ef218fb (Guard against out-of-bounds memory access when parsing LIMIT_HEAP et al (PCRE2Project#463), 2024-09-07), a malformed pattern could result in reading 1 byte past its end. Fix a similar issue that affects all VERBs and add test cases to ensure the original bug and all its siblings are no longer an issue. While at it fix the wording of the related documentation.
PhilipHazel
pushed a commit
that referenced
this pull request
Sep 22, 2024
As reported recently by ef218fb (Guard against out-of-bounds memory access when parsing LIMIT_HEAP et al (#463), 2024-09-07), a malformed pattern could result in reading 1 byte past its end. Fix a similar issue that affects all VERBs and add test cases to ensure the original bug and all its siblings are no longer an issue. While at it fix the wording of the related documentation.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
While fuzzing PCRE2, I found a case in which
pcre2_compile
may incorrectly read past the end of the pattern string which it is given. Here are the details:Patterns passed to
pcre2_compile
are not guaranteed to be null-terminated. Also, it can happen that there is an invalid pattern like this:If the next byte of memory after the end of the pattern happens to be a digit, it will be parsed as part of the limit value. Or, if the next byte is a right parenthesis character, it will be taken as the end of the
(*LIMIT_HEAP=nnn)
construct.This will result in
skipatstart
being larger thanpatlen
, which will result in underflow and an erroneous call to malloc requesting a huge number of bytes.