Skip to content

regex: Plug a regex literal crash#11938

Open
cosmo0920 wants to merge 2 commits into
masterfrom
cosmo0920-plug-regex-literal-crash
Open

regex: Plug a regex literal crash#11938
cosmo0920 wants to merge 2 commits into
masterfrom
cosmo0920-plug-regex-literal-crash

Conversation

@cosmo0920

@cosmo0920 cosmo0920 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Closes #11937.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

Bug Fixes

  • Fixed an out-of-bounds access issue when processing short or empty regex patterns, improving stability and preventing potential crashes.

Tests

  • Added comprehensive test coverage for regex patterns with literal slashes to validate edge case handling.

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 07df8bfa-f778-49ff-9629-df86813568ef

📥 Commits

Reviewing files that changed from the base of the PR and between b7f4f89 and ae73a25.

📒 Files selected for processing (2)
  • src/flb_regex.c
  • tests/internal/regex.c

📝 Walkthrough

Walkthrough

The PR fixes a crash in regex pattern parsing by preventing out-of-bounds access when validating pattern delimiters on short inputs. A length guard is added before delimiter detection, and comprehensive test cases document expected behavior for edge cases including single-slash and literal-slash patterns.

Changes

Regex Pattern Delimiter Parsing Fix

Layer / File(s) Summary
Bounds-check fix in str_to_regex()
src/flb_regex.c
str_to_regex() adds len > 1 guard before checking first and last characters for / delimiters, preventing out-of-bounds access on empty or single-character patterns while preserving delimiter-parsing for valid /pat/ forms.
Regex pattern delimiter edge-case tests
tests/internal/regex.c
Three new test functions validate literal / patterns, slash-delimited patterns like /tmp/, and escaped slash delimiters like //tmp//, with assertions on match behavior with and without surrounding delimiters. Tests are registered in TEST_LIST.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A regex that stumbles on single slashes bare,
Now guards against bounds with protective care,
Tests confirm that / stands alone with pride,
And //tmp// keeps its delimiters wide,
One-line fix, three tests—a rabbit's delight! 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the primary change: fixing a crash in regex literal handling when processing patterns like a single '/'.
Linked Issues check ✅ Passed The PR successfully addresses the crash requirement from issue #11937 by preventing out-of-bounds access when parsing single '/' patterns.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the regex literal crash issue and adding test coverage for the fix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cosmo0920-plug-regex-literal-crash

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cosmo0920 cosmo0920 added this to the Fluent Bit v5.0.8 milestone Jun 11, 2026
@cosmo0920

Copy link
Copy Markdown
Contributor Author

This Windows ARM64 fail https://github.com/fluent/fluent-bit/actions/runs/27324468341/job/80722539551?pr=11938 will be resolved with:
#11934
For 4.2:
#11935

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filtrer grep failed with pattern "/"

1 participant