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

Improve checking of the path lengths during Payments #4519

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions src/ripple/app/tx/impl/Payment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,27 +270,17 @@ Payment::preclaim(PreclaimContext const& ctx)
return tecDST_TAG_NEEDED;
}

if (paths || sendMax || !saDstAmount.native())
// Payment with at least one intermediate step and uses transitive balances.
if ((paths || sendMax || !saDstAmount.native()) && ctx.view.open())
{
// Ripple payment with at least one intermediate step and uses
// transitive balances.

// Copy paths into an editable class.
STPathSet const spsPaths = ctx.tx.getFieldPathSet(sfPaths);
STPathSet const& paths = ctx.tx.getFieldPathSet(sfPaths);

auto pathTooBig = spsPaths.size() > MaxPathSize;

if (!pathTooBig)
for (auto const& path : spsPaths)
if (path.size() > MaxPathLength)
{
pathTooBig = true;
break;
}

if (ctx.view.open() && pathTooBig)
if (paths.size() > MaxPathSize ||
std::any_of(paths.begin(), paths.end(), [](STPath const& path) {
return path.size() > MaxPathLength;
}))
{
return telBAD_PATH_COUNT; // Too many paths for proposed ledger.
return telBAD_PATH_COUNT;
}
}

Expand Down Expand Up @@ -384,9 +374,6 @@ Payment::doApply()
}
}

// Copy paths into an editable class.
STPathSet spsPaths = ctx_.tx.getFieldPathSet(sfPaths);

path::RippleCalc::Input rcInput;
rcInput.partialPaymentAllowed = partialPaymentAllowed;
rcInput.defaultPathsAllowed = defaultPathsAllowed;
Expand All @@ -404,7 +391,7 @@ Payment::doApply()
saDstAmount,
uDstAccountID,
account_,
spsPaths,
ctx_.tx.getFieldPathSet(sfPaths),
ctx_.app.logs(),
&rcInput);
// VFALCO NOTE We might not need to apply, depending
Expand Down