Skip to content

Modify vsnprintf condition checks for size#11878

Open
vast0906 wants to merge 2 commits into
fluent:masterfrom
vast0906:master
Open

Modify vsnprintf condition checks for size#11878
vast0906 wants to merge 2 commits into
fluent:masterfrom
vast0906:master

Conversation

@vast0906
Copy link
Copy Markdown

@vast0906 vast0906 commented May 28, 2026

Fixes #11876


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 internal string buffer handling and error detection to prevent rare edge-case overflows and off-by-one issues, enhancing stability and reliability.

Review Change Stack

Updated conditions in vsnprintf checks to include equality.

Signed-off-by: vast0906 <vast0906@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 92dda547-3ef3-41fe-89df-baae429a98fe

📥 Commits

Reviewing files that changed from the base of the PR and between 972ff20 and d774f5e.

📒 Files selected for processing (1)
  • src/flb_sds.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/flb_sds.c

📝 Walkthrough

Walkthrough

Two small fixes in SDS formatting: flb_sds_printf tightens the vsnprintf insatiable check at available-space boundaries; flb_sds_snprintf returns on negative vsnprintf and adjusts buffer-growth math (ret >= size, grow by ret - size + 1, set size = ret + 1).

Changes

SDS Buffer Boundary Handling

Layer / File(s) Summary
SDS format function boundary fixes
src/flb_sds.c
flb_sds_printf uses >= to detect an insatiable vsnprintf when output reaches available space. flb_sds_snprintf returns -1 for ret < 0, grows the SDS when (size_t)ret >= size by ret - size + 1 (for NUL), and sets size = ret + 1.

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs:

  • fluent/fluent-bit#10949: Tightens flb_sds_printf/flb_sds_snprintf sizing and off-by-one growth logic, related to SDS formatting used in ES header construction.

Suggested labels:
backport to v4.1.x, backport to v4.2.x

Suggested reviewers:

  • edsiper
  • cosmo0920
  • braydonk

I hopped through buffers late at night,
Counting bytes by soft moonlight,
Fixed the gap where NUL once slipped,
Now strings land whole — not half-equipped,
A quiet hop, a tidy byte! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 'Modify vsnprintf condition checks for size' accurately describes the main changes in flb_sds.c, which adjust the condition checks and buffer growth logic for vsnprintf handling.
Linked Issues check ✅ Passed The code changes directly address the core issue #11876 by fixing vsnprintf error handling and off-by-one buffer sizing bugs that caused malformed bulk bodies with embedded NUL bytes when ES output uses Id_Key plus Write_Operation.
Out of Scope Changes check ✅ Passed All changes in src/flb_sds.c are scoped to fixing vsnprintf condition checks and error handling, which are directly related to the buffer serialization issues described in linked issue #11876.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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_sds.c`:
- Around line 405-414: The vsnprintf retry path in flb_sds_snprintf can
mis-handle negative returns and leaks the va_list on error; after calling
vsnprintf (in the retry_snprintf block) first check if ret < 0 and if so call
va_end(va) and return -1, then perform the resize check using a size-safe
comparison (e.g. if ((size_t)ret >= size) or cast ret to size_t) before
computing the grow amount; also ensure any early returns (like tmp == NULL) call
va_end(va) before returning; update references to flb_sds_increase and the
va_list handling in flb_sds_snprintf accordingly.
🪄 Autofix (Beta)

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

Run ID: ff636f22-8d35-4a1b-a723-ebcd18438202

📥 Commits

Reviewing files that changed from the base of the PR and between 19cc8f9 and 972ff20.

📒 Files selected for processing (1)
  • src/flb_sds.c

Comment thread src/flb_sds.c
Signed-off-by: vast0906 <vast0906@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

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.

[out_es] Id_Key + Write_Operation produces unparseable bulk body ("no requests added") on 4.2.4

1 participant