Refactor sub_index validation logic in LedgerEntry#7548
Open
TLuca-coder210 wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview of change
This PR fixes issue #6770 by tightening the input validation for the
sub_indexparameter in theledger_entryRPC 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 usedisConvertibleTo(json::ValueType::UInt)which incorrectly returns true for negative integers (like-1). When.asUInt()was called later on line 389, it threw aJson::error, causing a poorrpcINTERNALerror path for API v1 users.This change updates the validation condition to strictly check for
isUInt()(or non-negative integers), routing invalid inputs correctly torpcINVALID_PARAMSviainvalidFieldError.API Impact
libxrplchangeBefore / After
{"sub_index": -1}passed validation but caused an unhandled internal exception inasUInt(), returningrpcINTERNAL.{"sub_index": -1}fails validation early and cleanly returnsrpcINVALID_PARAMSviainvalidFieldError.