Skip to content

log: mem: signv4: Plug possible memory errors - #12234

Open
cosmo0920 wants to merge 4 commits into
masterfrom
cosmo0920-plug-memory-errors
Open

log: mem: signv4: Plug possible memory errors#12234
cosmo0920 wants to merge 4 commits into
masterfrom
cosmo0920-plug-memory-errors

Conversation

@cosmo0920

@cosmo0920 cosmo0920 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Closes: #12205.


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

    • Improved log-cache handling when memory allocation fails.
    • Prevented oversized messages from causing invalid suppression checks.
    • Preserved existing cached content when updates cannot be allocated.
    • Improved cleanup after query formatting failures to prevent resource leaks.
  • Tests

    • Added fuzz testing for log-cache creation, message handling, duplicate suppression, oversized inputs, and allocation failures.

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

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This change hardens log-cache allocation and copy failure paths, adds an INT_MAX size guard, adds an OSS-Fuzz target with allocator fault injection, and cleans up resources when SignV4 query formatting fails.

Changes

Log cache hardening

Layer / File(s) Summary
Log cache failure-path fixes
src/flb_log.c
Adds allocation cleanup, an INT_MAX suppression guard, and failure-safe SDS buffer replacement.
OSS-Fuzz log cache coverage
tests/internal/fuzzers/CMakeLists.txt, tests/internal/fuzzers/log_cache_fuzzer.c, include/fluent-bit/flb_mem.h
Registers a log-cache fuzzer and exercises suppression, oversized messages, and injected allocation failures.

SignV4 query cleanup

Layer / File(s) Summary
Query formatting failure cleanup
src/flb_signv4.c
Frees allocated query-formatting resources before returning on failure.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: edsiper

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% 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
Linked Issues check ✅ Passed The change frees the unlinked entry, destroys the partial cache, and returns on SDS allocation failure, satisfying issue #12205.
Out of Scope Changes check ✅ Passed The fuzzing support and SignV4 cleanup address related allocation-failure paths and remain within the PR objectives.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the log, memory, and SignV4 memory-error fixes covered by the pull request.
✨ Finishing Touches 💡 1
📝 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-memory-errors

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/flb_log.c`:
- Around line 704-706: Move every listed control-block opening brace to its own
following line without changing behavior: update the if in src/flb_log.c lines
704-706; the for and if blocks in tests/internal/fuzzers/log_cache_fuzzer.c
lines 58-69, both if blocks at lines 86-96, and the if blocks at lines 106-108,
120-122, and 128-131; and the if in include/fluent-bit/flb_mem.h lines 103-105.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fd421061-9453-4dd7-a34b-e06e8e5ef4bc

📥 Commits

Reviewing files that changed from the base of the PR and between cf50b7e and 32ab6f5.

📒 Files selected for processing (4)
  • include/fluent-bit/flb_mem.h
  • src/flb_log.c
  • tests/internal/fuzzers/CMakeLists.txt
  • tests/internal/fuzzers/log_cache_fuzzer.c

Comment thread src/flb_log.c
@cosmo0920

This comment was marked as outdated.

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
@cosmo0920
cosmo0920 requested a review from a team as a code owner August 5, 2026 14:27
@cosmo0920 cosmo0920 changed the title log: mem: Plug possible memory errors log: mem: signv4: Plug possible memory errors Aug 5, 2026
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.

flb_log_cache_create: SDS allocation failure causes use-after-free

1 participant