Skip to content

fix(p2p): bound peer-supplied vector sizes in three NOTIFY handlers#194

Open
raw391 wants to merge 1 commit into
Beldex-Coin:devfrom
raw391:fix/p2p-notify-vector-bounds
Open

fix(p2p): bound peer-supplied vector sizes in three NOTIFY handlers#194
raw391 wants to merge 1 commit into
Beldex-Coin:devfrom
raw391:fix/p2p-notify-vector-bounds

Conversation

@raw391

@raw391 raw391 commented Jun 3, 2026

Copy link
Copy Markdown

Three NOTIFY handlers in cryptonote_protocol_handler.inl iterate a peer-supplied vector without checking its size first:

  • handle_notify_new_master_node_vote at line 937 walks arg.votes doing signature verification per element
  • handle_notify_new_transactions at line 1081 parses arg.txs under incoming_tx_lock
  • handle_request_fluffy_missing_tx at line 980 does per-index dup check + block tx lookup over arg.missing_tx_indices

The codebase already defines CURRENCY_PROTOCOL_MAX_OBJECT_REQUEST_COUNT and CURRENCY_PROTOCOL_MAX_TXS_REQUEST_COUNT at cryptonote_protocol_handler.h:56-57 and uses them in handle_request_get_blocks (line 1190) and handle_notify_request_get_txs (line 1737). This PR adds the same pattern to the three vote/tx/fluffy handlers, plus CURRENCY_PROTOCOL_MAX_FLASHES_COUNT for the flash batch size in handle_notify_new_transactions.

Cap values: 1000 votes (50x current max quorum), 5000 txs and 500 missing-tx indices reuse existing constants, 1000 flashes matches the votes ceiling. LOG_ERROR_CCONTEXT matches the existing sibling pattern at lines 1190 and 1737.

handle_notify_new_master_node_vote, handle_notify_new_transactions
and handle_request_fluffy_missing_tx iterate a peer-supplied vector
without a size cap. The codebase already defines
CURRENCY_PROTOCOL_MAX_OBJECT_REQUEST_COUNT and
CURRENCY_PROTOCOL_MAX_TXS_REQUEST_COUNT for the same pattern in
handle_request_get_blocks and handle_notify_request_get_txs.

Adds CURRENCY_PROTOCOL_MAX_VOTES_COUNT and
CURRENCY_PROTOCOL_MAX_FLASHES_COUNT, drops oversized messages with
LOG_ERROR_CCONTEXT matching the existing sibling pattern.
@raw391 raw391 force-pushed the fix/p2p-notify-vector-bounds branch from e72939d to c96063c Compare June 5, 2026 15:59
@victor-tucci

Copy link
Copy Markdown
Member

With 30s blocks:
2 hours = 7200 / 30 = 240 blocks
checkpoint every 4 blocks = about 240 / 4 = 60 checkpoint rounds in vote lifetime
each checkpoint round has up to 20 votes

So worst-case checkpoint vote backlog is roughly:
60 * 20 = 1200 votes

That is above:
CURRENCY_PROTOCOL_MAX_VOTES_COUNT = 1000

So with 30s blocks, it is possible to exceed the max limit if enough checkpoint votes accumulate into one P2P relay batch. @raw391

@victor-tucci

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 2, 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.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4e1a7eea-bd6a-4717-ac43-5af3415c0c93

📥 Commits

Reviewing files that changed from the base of the PR and between c8e54f6 and c96063c.

📒 Files selected for processing (2)
  • src/cryptonote_protocol/cryptonote_protocol_handler.h
  • src/cryptonote_protocol/cryptonote_protocol_handler.inl

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Strengthened network request validation to reject oversized peer messages earlier.
    • Peers sending excessively large vote, transaction, flash, or missing-item requests may now be disconnected to help keep the network stable and responsive.
    • Added clearer protection against malformed or unusually large incoming data.

Walkthrough

New maximum count constants for votes and flashes are added, and three P2P protocol handlers now validate incoming request sizes against these and existing limits, disconnecting peers whose requests exceed the thresholds.

Changes

Oversized request rejection

Layer / File(s) Summary
Protocol limit constants and size validation
src/cryptonote_protocol/cryptonote_protocol_handler.h, src/cryptonote_protocol/cryptonote_protocol_handler.inl
Adds CURRENCY_PROTOCOL_MAX_VOTES_COUNT and CURRENCY_PROTOCOL_MAX_FLASHES_COUNT constants; handle_notify_new_master_node_vote, handle_request_fluffy_missing_tx, and handle_notify_new_transactions now check list sizes against these and CURRENCY_PROTOCOL_MAX_OBJECT_REQUEST_COUNT/CURRENCY_PROTOCOL_MAX_TXS_REQUEST_COUNT, logging an error and dropping the connection when exceeded.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Peer
  participant ProtocolHandler
  participant Connection

  Peer->>ProtocolHandler: notify_new_master_node_vote / request_fluffy_missing_tx / notify_new_transactions
  ProtocolHandler->>ProtocolHandler: check size against MAX_* limit
  alt size exceeds limit
    ProtocolHandler->>Connection: drop_connection(context, false, false)
    ProtocolHandler-->>Peer: return 1
  else size within limit
    ProtocolHandler->>ProtocolHandler: continue normal processing
  end
Loading

Poem

A rabbit hops the network line,
Counting votes and flashes fine,
Too many? Snip, the link is cut,
No oversized bundle clogs this hutch!
Hop, hop—safe and tidy code. 🐇📦

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding bounds checks for peer-supplied vectors in NOTIFY handlers.
Description check ✅ Passed The description clearly matches the patch and explains the added size checks and limits in the affected handlers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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