Skip to content

Refactor sub_index validation logic in LedgerEntry#7548

Open
TLuca-coder210 wants to merge 2 commits into
XRPLF:developfrom
TLuca-coder210:develop
Open

Refactor sub_index validation logic in LedgerEntry#7548
TLuca-coder210 wants to merge 2 commits into
XRPLF:developfrom
TLuca-coder210:develop

Conversation

@TLuca-coder210

@TLuca-coder210 TLuca-coder210 commented Jun 16, 2026

Copy link
Copy Markdown

Overview of change

This PR fixes issue #6770 by tightening the input validation for the sub_index parameter in the ledger_entry RPC handler (LedgerEntry.cpp). It ensures that malformed negative requests return a clean validation error instead of throwing an unhandled jsoncpp exception.

Context of Change

In parseDirectory, the code used isConvertibleTo(json::ValueType::UInt) which incorrectly returns true for negative integers (like -1). When .asUInt() was called later on line 389, it threw a Json::error, causing a poor rpcINTERNAL error path for API v1 users.

This change updates the validation condition to strictly check for isUInt() (or non-negative integers), routing invalid inputs correctly to rpcINVALID_PARAMS via invalidFieldError.

API Impact

  • Public API: Breaking change (Fixes error response consistency for API v1 from rpcINTERNAL to rpcINVALID_PARAMS on invalid negative bounds)
  • Public API: New feature
  • libxrpl change
  • Peer protocol change

Before / After

  • Before: Sending {"sub_index": -1} passed validation but caused an unhandled internal exception in asUInt(), returning rpcINTERNAL.
  • After: Sending {"sub_index": -1} fails validation early and cleanly returns rpcINVALID_PARAMS via invalidFieldError.

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