Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle invalid marker parameter in grpc call #5317

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

cindyyan317
Copy link
Collaborator

Handle invalid marker parameter in grpc call

Context of Change

end_marker is used to limit the range of ledger entries to fetch
If end_marker is less than marker, crash can happen at https://github.com/XRPLF/rippled/blob/develop/src/xrpld/rpc/handlers/LedgerData.cpp#L185

Type of Change

  • [ x] Bug fix (non-breaking change which fixes an issue)

Before

rippled server crashes if end_marker is smaller than marker.

After

Return code = InvalidArgument desc = end marker malformed error to grpc caller.

Test

Test manually

This PR is to address the crash. Developing unit test setup for grpc server methods is beyond the scope of this PR.

Copy link

codecov bot commented Feb 25, 2025

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 78.1%. Comparing base (c1c2b5b) to head (c7c5cd7).

Files with missing lines Patch % Lines
src/xrpld/rpc/handlers/LedgerData.cpp 0.0% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #5317   +/-   ##
=======================================
  Coverage     78.1%   78.1%           
=======================================
  Files          790     790           
  Lines        67908   67909    +1     
  Branches      8228    8229    +1     
=======================================
+ Hits         53024   53025    +1     
  Misses       14884   14884           
Files with missing lines Coverage Δ
src/xrpld/rpc/handlers/LedgerData.cpp 57.1% <0.0%> (-0.6%) ⬇️

... and 1 file with indirect coverage changes

Impacted file tree graph

Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

In addition to the change below, is it possible to write some unit tests for this functionality?

@cindyyan317
Copy link
Collaborator Author

In addition to the change below, is it possible to write some unit tests for this functionality?

@ximinez
I believe the current version of rippled doesn't have a unit test setup for gRPC methods. Based on my limited understanding of rippled, setting up unit tests for gRPC seems more complex than fixing the crash itself.

If there's existing unit test scaffolding for gRPC calls, similar to env.rpc, I'm happy to add tests. Otherwise, I'd prefer to focus on fixing the crash in this PR rather than setting up additional framework components.

@cindyyan317 cindyyan317 requested a review from ximinez February 26, 2025 09:48
@ximinez
Copy link
Collaborator

ximinez commented Feb 27, 2025

If there's existing unit test scaffolding for gRPC calls, similar to env.rpc, I'm happy to add tests. Otherwise, I'd prefer to focus on fixing the crash in this PR rather than setting up additional framework components.

I thought we had some, but I can't find them now, so I guess we can move forward as-is.

Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

Looks good

@vlntb vlntb self-requested a review March 3, 2025 13:41
grpc::Status errorStatus{
grpc::StatusCode::INVALID_ARGUMENT, "end marker malformed"};
return {response, errorStatus};
if (auto const key = uint256::fromVoidChecked(request.end_marker());
Copy link
Collaborator

@vlntb vlntb Mar 3, 2025

Choose a reason for hiding this comment

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

[nit]: It might be useful to differentiate between null and wrong position of marker. I.e.:

    auto key = uint256::fromVoidChecked(request.end_marker());

    if (!key)
    {
        return {response, {grpc::StatusCode::INVALID_ARGUMENT, "end marker malformed"}};
    }

    if (*key < startKey)
    {
        return {response, {grpc::StatusCode::INVALID_ARGUMENT, "end marker out of range"}};
    }

    e = ledger->sles.upper_bound(*key);

Copy link
Collaborator

@vlntb vlntb left a comment

Choose a reason for hiding this comment

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

LGTM, happy to approve once nit comment is answered.
p.s. I checked and can confirm that it is not very easy to add unit-test in this case.

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