Skip to content

fix: bound InputMessenger non-protocol handlers - #3714

Merged
chenBright merged 4 commits into
apache:masterfrom
songgaoye:fix/input-messenger-handler-capacity
Nov 21, 2026
Merged

chenBright merged 4 commits into
apache:masterfrom
songgaoye:fix/input-messenger-handler-capacity

Conversation

@songgaoye

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

InputMessenger::AddNonProtocolHandler() increments _max_index and writes
to _handlers[index] without checking whether index is within _capacity.

Registering more non-protocol handlers than the configured capacity therefore
writes past the handler array.

What is changed and the side effects?

Changed:

  • Check the next handler index against _capacity before accessing
    _handlers[index].
  • Return -1 and log an error when the non-protocol handler capacity is
    exhausted.
  • Add regression coverage with an InputMessenger of capacity one.

Side effects:

  • Performance effects:

    Adds one bounds check during non-protocol handler registration, which is
    setup-time work and not on the message-processing path.

  • Breaking backward compatibility:

    Calls that previously overflowed the configured handler capacity now fail
    cleanly with -1.


Check List:

@chenBright
chenBright requested a lite review from Copilot November 5, 2026 15:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
What changed in this PR

Fixes an out-of-bounds write in InputMessenger::AddNonProtocolHandler() by enforcing the configured non-protocol handler capacity and adds a regression test to prevent future overflow.

Changes:

  • Add a capacity bounds check before writing to _handlers[index] and return -1 on exhaustion.
  • Log an error when the non-protocol handler capacity is exceeded.
  • Add a unit test covering capacity=1 behavior (second registration fails).
File Description
src/​brpc/​input_messenger.cpp Prevents handler-array overflow by validating the next handler index against _capacity.
test/​brpc_input_messenger_unittest.cpp Adds regression coverage ensuring non-protocol handler registration respects capacity limits.

Review effort: Lite

Comment thread src/brpc/input_messenger.cpp Resolved
Comment thread test/brpc_input_messenger_unittest.cpp Resolved
@songgaoye
songgaoye force-pushed the fix/input-messenger-handler-capacity branch from 836faa6 to b830d0f Compare November 8, 2026 03:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported, and the change includes a bounds check with regression coverage for handler-capacity exhaustion.

No open issues 🎉

2 resolved since last review

Review effort: Lite

@chenBright chenBright left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@chenBright
chenBright merged commit 1b075b2 into apache:master Nov 21, 2026
29 checks passed
@songgaoye
songgaoye deleted the fix/input-messenger-handler-capacity branch November 21, 2026 09:09
darion-yaphet pushed a commit to darion-yaphet/brpc that referenced this pull request Nov 25, 2026
* fix: bound InputMessenger non-protocol handlers

* Fix non-protocol handler capacity logging and test setup
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