Skip to content

Fix a potential out of bounds read when building a XbBuilderNode - #335

Merged
hughsie merged 1 commit into
mainfrom
hughsie/xb_strsplit
Jul 31, 2026
Merged

hughsie merged 1 commit into
mainfrom
hughsie/xb_strsplit

Conversation

@hughsie

@hughsie hughsie commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Although xb_builder_node_set_text() is normally NUL-terminated, it doesn't have to be. Split the string taking into account the possibility that NUL is missing.

Found by Aisle Research, many thanks.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of length-limited text input, including buffers that are not NUL-terminated.
    • Preserved embedded newline content when processing builder-node text.
  • Tests

    • Added coverage for zero-length input, NUL-terminated strings and embedded newline data.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f401b788-1e2b-4eeb-a090-b541878f2394

📥 Commits

Reviewing files that changed from the base of the PR and between d8959ba and 158237c.

📒 Files selected for processing (4)
  • src/xb-builder-node.c
  • src/xb-common-private.h
  • src/xb-common.c
  • src/xb-self-test.c
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/xb-common.c
  • src/xb-common-private.h
  • src/xb-builder-node.c
  • src/xb-self-test.c

📝 Walkthrough

Walkthrough

The change adds xb_strsplit() for length-bounded input processing. Builder-node text splitting now uses the safe text length. Tests cover zero-length, NUL-terminated, and explicitly sized buffers.

Changes

Bounded text splitting

Layer / File(s) Summary
Common split helper
src/xb-common-private.h, src/xb-common.c
Adds xb_strsplit() with input validation and duplication for bounded data without a terminating NUL.
Builder-node integration and tests
src/xb-builder-node.c, src/xb-self-test.c
Uses xb_strsplit() with text_len_safe and adds builder-node tests for zero-length, NUL-terminated, and explicitly sized input.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% 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 clearly and concisely describes the main change: preventing an out-of-bounds read in XbBuilderNode construction.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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/xb-self-test.c`:
- Around line 2698-2707: The xb_builder_node_nul_func test does not verify the
text set on root. After each xb_builder_node_set_text call, read back or export
the node and assert the expected result, including the explicitly sized A\nB
buffer case; retain coverage for the zero-length input without treating it as
xb_strsplit coverage.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c491036-51a6-4520-a3a8-40bcbeccec3e

📥 Commits

Reviewing files that changed from the base of the PR and between 9366f7e and d8959ba.

📒 Files selected for processing (4)
  • src/xb-builder-node.c
  • src/xb-common-private.h
  • src/xb-common.c
  • src/xb-self-test.c

Comment thread src/xb-self-test.c
Although xb_builder_node_set_text() is normally NUL-terminated, it doesn't have
to be. Split the string taking into account the possibility that NUL is missing.

Found by Aisle Research, many thanks.
@hughsie
hughsie force-pushed the hughsie/xb_strsplit branch from d8959ba to 158237c Compare July 31, 2026 09:33
@hughsie

hughsie commented Jul 31, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@hughsie
hughsie merged commit d9dbfb1 into main Jul 31, 2026
4 checks passed
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.

1 participant