-
Notifications
You must be signed in to change notification settings - Fork 201
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
Add test and fix for buffer over-read in pcre2grep #594
Add test and fix for buffer over-read in pcre2grep #594
Conversation
cedb976
to
02701bc
Compare
@@ -99,10 +99,9 @@ POSSIBILITY OF SUCH DAMAGE. | |||
#include <bzlib.h> | |||
#endif | |||
|
|||
#include "pcre2_util.h" | |||
|
|||
#define PCRE2_CODE_UNIT_WIDTH 8 | |||
#include "pcre2.h" |
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.
The original idea of pcre2grep was that it was something an external PCRE2 user could have written. In that spirit, it is not right to #include any of the internal pcre2....h files such as pcre2_util.h or pcre2_internal.h.
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.
Ah I see. So it's OK for pcre2test to use those, but pcre2grep is an "external" client of the API.
I can do that. It would be useful to have assertions though...
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.
Yes, that''s exactly it; pcre2test has "internal" knowledge because of what it is and various tests that it can't do without that knowledge. I have to confess that I have never really got to grips with assertions. Entirely my fault! Glad to see this lack is being addressed.
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.
Note though that the assertions were added to pcre2_util.h
instead of other internal header file, thinking it might be useful also for non internal use.
I fixed/rewritten the UTF-8 decoding in pcre2grep to be much more cautious about not running over the end of the buffer. The new test now passes in valgrind. |
The patch looks good, but I am not a pcre2grep expert. It seems invalid utf is not really supported in pcre2grep, but at least it does not do buffer overruns anymore. As far as I remember pcre2grep is just an "example" tool, not intended for production, although some people use it for whatever reason. |
It sounds like you've looked at it @zherczeg - I think I can merge? |
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
Found by Clang-Analyze in #576
This test fails without the code fix, which required correcting the way the pcre2grep tests are run with valgrind.
The new test passes with the code changes made.