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

Two minor correctness bugs found by Clang Analyzer #576

Closed
NWilson opened this issue Nov 22, 2024 · 0 comments
Closed

Two minor correctness bugs found by Clang Analyzer #576

NWilson opened this issue Nov 22, 2024 · 0 comments

Comments

@NWilson
Copy link
Member

NWilson commented Nov 22, 2024

I have a PR open which adds Clang's very good static analyzer to our reports.

This has flagged two issues, one of which appears to be a genuine bug:

  • In pcre2grep, the end_of_line function is naughty! It looks at the leading byte of a UTF-8 sequence to find out how many bytes to read, then reads them without checking whether the buffer contains enough bytes! It appears to be a read-past-the-end bug if the input ends in a truncated UTF-8 sequence.
  • In pcre2posix, the pcre2_regerror has a NULL check for preg, and the function does support passing in a NULL preg. But further down in the function, it's used unconditionally in message_len(message, (int)preg->re_erroffset), and clang reckons that a NULL dereference (might) be possible there. I believe that this is bogus, however, and clang just isn't quite clever enough to work it out; but someone should probably double-check that reasoning.
NWilson added a commit to NWilson/pcre2 that referenced this issue Dec 3, 2024
NWilson added a commit to NWilson/pcre2 that referenced this issue Dec 4, 2024
NWilson added a commit to NWilson/pcre2 that referenced this issue Dec 6, 2024
NWilson added a commit that referenced this issue Dec 6, 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 added a commit that referenced this issue Dec 7, 2024
One of these appears in Coverity's dashboard; the rest are from clang-scan.

See #576
@NWilson NWilson closed this as completed Dec 9, 2024
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

No branches or pull requests

1 participant