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

Improve validation for StringMatchFilter for null/empty text #3153 #3158

Merged
merged 5 commits into from
Nov 3, 2024

Conversation

JWT007
Copy link
Contributor

@JWT007 JWT007 commented Nov 3, 2024

This should fix a potential NPE in StringMatchFilter if the 'text' field is not set or set to null/empty string. #3153

  • Added '@required' to @PluginAttribute
  • removed default value of ""
  • added notEmpty assert to Builder setText
  • added notEmpty assert to StringMatchFilter constructor.
  • added changelog XML file.

Checklist

  • Base your changes on 2.x branch if you are targeting Log4j 2; use main otherwise
  • ./mvnw verify succeeds (if it fails due to code formatting issues reported by Spotless, simply run ./mvnw spotless:apply and retry)
  • Non-trivial changes contain an entry file in the src/changelog/.2.x.x directory
  • Tests for the changes are provided
  • Commits are signed (optional, but highly recommended)

Copy link

github-actions bot commented Nov 3, 2024

Job Requested goals Build Tool Version Build Outcome Build Scan®
build-macos-latest clean install 3.9.8 Build Scan PUBLISHED
build-ubuntu-latest clean install 3.9.8 Build Scan PUBLISHED
build-windows-latest clean install 3.9.8 Build Scan PUBLISHED
Generated by gradle/develocity-actions

@ppkarwasz
Copy link
Contributor

@JWT007,

Thank you for your contribution. Can you add some unit tests to the PR?

@JWT007
Copy link
Contributor Author

JWT007 commented Nov 3, 2024

Hi @ppkarwasz I looked to see if I could extend an existing test for StringMatchFilter but there were no existing unit-tests.

@ppkarwasz
Copy link
Contributor

Hi @ppkarwasz I looked to see if I could extend an existing test for StringMatchFilter but there were no existing unit-tests.

Yes, it happens. 😉 Can you create a StringMatchFilterTest in the log4j-core-test module and test the two conditions you fixed (build() returns null if setMatchString is not called and setMatchString throws if null or an empty string is used as paramter).

Copy link
Contributor

@ppkarwasz ppkarwasz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@ppkarwasz ppkarwasz merged commit f592d29 into apache:2.x Nov 3, 2024
9 checks passed
@JWT007 JWT007 deleted the bugfix/LOG4J-3153 branch November 3, 2024 21:29
@ppkarwasz ppkarwasz mentioned this pull request Nov 4, 2024
23 tasks
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.

3 participants