Skip to content

Commit

Permalink
Check all the failure points
Browse files Browse the repository at this point in the history
  • Loading branch information
ximinez committed Aug 16, 2023
1 parent 5d05d44 commit 4c9bb17
Show file tree
Hide file tree
Showing 2 changed files with 283 additions and 37 deletions.
121 changes: 93 additions & 28 deletions src/ripple/rpc/handlers/LedgerEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,21 @@ doLedgerEntry(RPC::JsonContext& context)
}
else if (context.params.isMember(jss::account_root))
{
expectedType = ltACCOUNT_ROOT;
auto const account = parseBase58<AccountID>(
context.params[jss::account_root].asString());
if (!account || account->isZero())
jvResult[jss::error] = "malformedAddress";
if (context.apiVersion > 1u &&
!context.params[jss::account_root].isString())
{
jvResult[jss::error] = "invalidParams";
}
else
uNodeIndex = keylet::account(*account).key;
{
expectedType = ltACCOUNT_ROOT;
auto const account = parseBase58<AccountID>(
context.params[jss::account_root].asString());
if (!account || account->isZero())
jvResult[jss::error] = "malformedAddress";
else
uNodeIndex = keylet::account(*account).key;
}
}
else if (context.params.isMember(jss::check))
{
Expand Down Expand Up @@ -178,6 +186,12 @@ doLedgerEntry(RPC::JsonContext& context)
// May not specify both dir_root and owner.
jvResult[jss::error] = "malformedRequest";
}
else if (
context.apiVersion > 1u &&
!context.params[jss::directory][jss::dir_root].isString())
{
jvResult[jss::error] = "invalidParams";
}
else if (!uDirRoot.parseHex(
context.params[jss::directory][jss::dir_root]
.asString()))
Expand All @@ -192,17 +206,26 @@ doLedgerEntry(RPC::JsonContext& context)
}
else if (context.params[jss::directory].isMember(jss::owner))
{
auto const ownerID = parseBase58<AccountID>(
context.params[jss::directory][jss::owner].asString());

if (!ownerID)
if (context.apiVersion > 1u &&
!context.params[jss::directory][jss::owner].isString())
{
jvResult[jss::error] = "malformedAddress";
jvResult[jss::error] = "invalidParams";
}
else
{
uNodeIndex =
keylet::page(keylet::ownerDir(*ownerID), uSubIndex).key;
auto const ownerID = parseBase58<AccountID>(
context.params[jss::directory][jss::owner].asString());

if (!ownerID)
{
jvResult[jss::error] = "malformedAddress";
}
else
{
uNodeIndex =
keylet::page(keylet::ownerDir(*ownerID), uSubIndex)
.key;
}
}
}
else
Expand All @@ -216,7 +239,13 @@ doLedgerEntry(RPC::JsonContext& context)
expectedType = ltESCROW;
if (!context.params[jss::escrow].isObject())
{
if (!uNodeIndex.parseHex(context.params[jss::escrow].asString()))
if (context.apiVersion > 1u &&
!context.params[jss::escrow].isString())
{
jvResult[jss::error] = "invalidParams";
}
else if (!uNodeIndex.parseHex(
context.params[jss::escrow].asString()))
{
uNodeIndex = beast::zero;
jvResult[jss::error] = "malformedRequest";
Expand All @@ -229,6 +258,12 @@ doLedgerEntry(RPC::JsonContext& context)
{
jvResult[jss::error] = "malformedRequest";
}
else if (
context.apiVersion > 1u &&
!context.params[jss::escrow][jss::owner].isString())
{
jvResult[jss::error] = "invalidParams";
}
else
{
auto const id = parseBase58<AccountID>(
Expand All @@ -247,7 +282,13 @@ doLedgerEntry(RPC::JsonContext& context)
expectedType = ltOFFER;
if (!context.params[jss::offer].isObject())
{
if (!uNodeIndex.parseHex(context.params[jss::offer].asString()))
if (context.apiVersion > 1u &&
!context.params[jss::offer].isString())
{
jvResult[jss::error] = "invalidParams";
}
else if (!uNodeIndex.parseHex(
context.params[jss::offer].asString()))
{
uNodeIndex = beast::zero;
jvResult[jss::error] = "malformedRequest";
Expand All @@ -260,6 +301,12 @@ doLedgerEntry(RPC::JsonContext& context)
{
jvResult[jss::error] = "malformedRequest";
}
else if (
context.apiVersion > 1u &&
!context.params[jss::offer][jss::account].isString())
{
jvResult[jss::error] = "invalidParams";
}
else
{
auto const id = parseBase58<AccountID>(
Expand All @@ -277,8 +324,13 @@ doLedgerEntry(RPC::JsonContext& context)
{
expectedType = ltPAYCHAN;

if (!uNodeIndex.parseHex(
context.params[jss::payment_channel].asString()))
if (context.apiVersion > 1u &&
!context.params[jss::payment_channel].isString())
{
jvResult[jss::error] = "invalidParams";
}
else if (!uNodeIndex.parseHex(
context.params[jss::payment_channel].asString()))
{
uNodeIndex = beast::zero;
jvResult[jss::error] = "malformedRequest";
Expand Down Expand Up @@ -312,6 +364,12 @@ doLedgerEntry(RPC::JsonContext& context)
{
jvResult[jss::error] = "malformedAddress";
}
else if (
context.apiVersion > 1u &&
!jvRippleState[jss::currency].isString())
{
jvResult[jss::error] = "invalidParams";
}
else if (!to_currency(
uCurrency, jvRippleState[jss::currency].asString()))
{
Expand All @@ -328,7 +386,13 @@ doLedgerEntry(RPC::JsonContext& context)
expectedType = ltTICKET;
if (!context.params[jss::ticket].isObject())
{
if (!uNodeIndex.parseHex(context.params[jss::ticket].asString()))
if (context.apiVersion > 1u &&
!context.params[jss::ticket].isString())
{
jvResult[jss::error] = "invalidParams";
}
else if (!uNodeIndex.parseHex(
context.params[jss::ticket].asString()))
{
uNodeIndex = beast::zero;
jvResult[jss::error] = "malformedRequest";
Expand All @@ -341,6 +405,12 @@ doLedgerEntry(RPC::JsonContext& context)
{
jvResult[jss::error] = "malformedRequest";
}
else if (
context.apiVersion > 1u &&
!context.params[jss::ticket][jss::account].isString())
{
jvResult[jss::error] = "invalidParams";
}
else
{
auto const id = parseBase58<AccountID>(
Expand All @@ -358,15 +428,6 @@ doLedgerEntry(RPC::JsonContext& context)

if (context.params[jss::nft_page].isString())
{
// XRPL Doc states "nft_page" field is a string. check for this
// apiVersion 2 onwards. invalidParam error is thrown if the above
// condition is false
if (context.apiVersion > 1u &&
!context.params[jss::nft_page].isString())
{
uNodeIndex = beast::zero;
jvResult[jss::error] = "invalidParams";
}
if (!uNodeIndex.parseHex(context.params[jss::nft_page].asString()))
{
uNodeIndex = beast::zero;
Expand All @@ -383,7 +444,11 @@ doLedgerEntry(RPC::JsonContext& context)
expectedType = ltAMM;
if (!context.params[jss::amm].isObject())
{
if (!uNodeIndex.parseHex(context.params[jss::amm].asString()))
if (context.apiVersion > 1u && !context.params[jss::amm].isString())
{
jvResult[jss::error] = "invalidParams";
}
else if (!uNodeIndex.parseHex(context.params[jss::amm].asString()))
{
uNodeIndex = beast::zero;
jvResult[jss::error] = "malformedRequest";
Expand Down
Loading

0 comments on commit 4c9bb17

Please sign in to comment.