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

Add test and fix for buffer over-read in pcre2grep #594

Merged

Conversation

NWilson
Copy link
Member

@NWilson NWilson commented Dec 3, 2024

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.

@NWilson NWilson force-pushed the user/niwilson/pcre2grep-valgrind branch from cedb976 to 02701bc Compare December 3, 2024 22:08
@@ -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"
Copy link
Collaborator

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.

Copy link
Member Author

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...

Copy link
Collaborator

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.

Copy link
Contributor

@carenas carenas Dec 4, 2024

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.

@NWilson NWilson changed the title Add test for buffer over-read in pcre2grep Add test and fix for buffer over-read in pcre2grep Dec 4, 2024
@NWilson
Copy link
Member Author

NWilson commented Dec 4, 2024

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.

@zherczeg
Copy link
Collaborator

zherczeg commented Dec 6, 2024

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.

@NWilson
Copy link
Member Author

NWilson commented Dec 6, 2024

It sounds like you've looked at it @zherczeg - I think I can merge?

Copy link
Collaborator

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@NWilson NWilson merged commit 30320bb into PCRE2Project:master Dec 6, 2024
21 checks passed
@NWilson NWilson deleted the user/niwilson/pcre2grep-valgrind branch December 6, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants