-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix account_objects with invalid marker do not return an error #5046
Conversation
f5edf6f
to
6117405
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #5046 +/- ##
=======================================
Coverage 77.5% 77.5%
=======================================
Files 777 777
Lines 65828 65831 +3
Branches 8207 8185 -22
=======================================
+ Hits 50995 51025 +30
+ Misses 14833 14806 -27
|
13b6555
to
e66a096
Compare
e66a096
to
627655e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this bug. I have some comments which would hopefully make this fix a little better.
src/test/rpc/AccountObjects_test.cpp
Outdated
auto resp = env.rpc("json", "account_objects", to_string(params)); | ||
auto& accountObjects = resp[jss::result][jss::account_objects]; | ||
BEAST_EXPECT(!resp[jss::result].isMember(jss::error)); | ||
BEAST_EXPECT( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also add here check that this is the last page:
BEAST_EXPECT(!resp[jss::result].isMember(jss::marker));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
// check if dirIndex is valid | ||
if (!dirIndex.isZero() && !ledger->read({ltDIR_NODE, dirIndex})) | ||
return RPC::invalid_field_error(jss::marker); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since RPC::getAccountObjects
returning false
would have the same result, I would move this check into the body of RPC::getAccountObjects
; this will keep the checks (other than the marker
format, in the code segment above) in that one function only, which is more robust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
src/xrpld/rpc/detail/RPCHelpers.cpp
Outdated
// non-zero dirIndex validity was checked in the caller function; | ||
// by this point, it should be zero. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as commented elsewhere, I would prefer if this function did not rely on the validation of dirIndex
happening in the caller, but rather move that check into the body of getAccountObjects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
While you are at it, I see that EDIT: If you want to see coverage on your local computer, without waiting for codecov.io to catch up on your branch, see instructions in https://github.com/XRPLF/rippled/blob/develop/BUILD.md#coverage-report . You will need Linux, gcc compiler and Python package
That will create |
Yes. I just added. There might be a potential bug here, if we pass in some marker like
|
It would be great to fix it, yes - @mDuo13 any comments ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice !
3e63249
to
1bc0bc9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good change, just some comments to improve unit tests.
return RPC::invalid_field_error(jss::marker); | ||
|
||
if (!entryIndex.parseHex(s)) | ||
if (!entryIndex.parseHex(markerStr.substr(idx + 1))) | ||
return RPC::invalid_field_error(jss::marker); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really nice improvement in parsing here ! 👍
src/test/rpc/AccountObjects_test.cpp
Outdated
std::stringstream ss(marker.asString()); | ||
std::string s; | ||
std::getline(ss, s, ','); | ||
s = s + ",0"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you pls also test when this gets corrupted not by ,0
but by a ,
alone ? i.e. valid dirIndex
followed by a coma, then end of string. Also reverse, i.e. string starts with a coma, followed by valid entryIndex
, then end of string. Reading up the implementation these both should return the same kind of error, but you need to have unit tests so that the code (which I think is good at this moment) does not degrade due to bad changes in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. In the recent commit, I added a lambda function to test invalid marker situations. And also added more invalid marker cases.
src/test/rpc/AccountObjects_test.cpp
Outdated
// test invalid marker by adding invalid string after the maker. | ||
{ | ||
std::string s = marker.asString(); | ||
s.append(",1234"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest replacing this test with a different one, where entryIndex
is valid, see my other comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used to test adding some extra characters after the entryIndex. The marker format is like xxxx,yyyy,1234
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I missed it.
abb9d23
to
141349c
Compare
@yinyiqian1 I allowed myself to merge the current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good change, just minor remarks on unit tests.
src/test/rpc/AccountObjects_test.cpp
Outdated
auto testInvalidMarker = [&env, &bob](std::string& marker) { | ||
Json::Value params; | ||
params[jss::account] = bob.human(); | ||
params[jss::limit] = 11; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... then you will be able to use limit
here, without explicit capture.
auto const markerStr = marker.asString(); | ||
auto const& idx = markerStr.find(','); | ||
auto const dirIndex = markerStr.substr(0, idx); | ||
auto const entryIndex = markerStr.substr(idx + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice !
nice ! @yinyiqian1 do you agree this is ready to merge ? |
09f19ff
to
66857f0
Compare
@Bronek And in the most recent commit, when the marker is "0,entryIndex", and entryIndex is valid, it will succeed. Because when dirIndex=0, we will use root.key as dirIndex. Please check my most recent commit. Thank you. |
@mDuo13 I think this PR does not require change in |
Yes, this sounds like a bug fix that does not require an API version change. |
fix #4542
High Level Overview of Change
Context of Change
Type of Change
.gitignore
, formatting, dropping support for older tooling)API Impact
libxrpl
change (any change that may affectlibxrpl
or dependents oflibxrpl
)