From 7dc2fe9ce79de22a0aa8657f90673efb0514bf04 Mon Sep 17 00:00:00 2001 From: seelabs Date: Tue, 9 May 2017 18:14:42 -0400 Subject: [PATCH] Handle strand creation for erroneous self-payment --- src/ripple/app/paths/RippleCalc.cpp | 2 +- src/ripple/app/paths/impl/PaySteps.cpp | 5 ++++- src/test/app/Flow_test.cpp | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ripple/app/paths/RippleCalc.cpp b/src/ripple/app/paths/RippleCalc.cpp index 34a0fe2380..41e1f6197c 100644 --- a/src/ripple/app/paths/RippleCalc.cpp +++ b/src/ripple/app/paths/RippleCalc.cpp @@ -147,7 +147,7 @@ RippleCalc::Output RippleCalc::rippleCalculate ( } catch (std::exception& e) { - JLOG (j.trace()) << "Exception from flow" << e.what (); + JLOG (j.error()) << "Exception from flow: " << e.what (); if (!useFlowV1Output) Rethrow(); } diff --git a/src/ripple/app/paths/impl/PaySteps.cpp b/src/ripple/app/paths/impl/PaySteps.cpp index ae43ecaf35..5ecce2cb19 100644 --- a/src/ripple/app/paths/impl/PaySteps.cpp +++ b/src/ripple/app/paths/impl/PaySteps.cpp @@ -101,7 +101,7 @@ toStep ( if (e1->isOffer() && e2->isAccount()) { // should already be taken care of - JLOG (j.warn()) + JLOG (j.error()) << "Found offer/account payment step. Aborting payment strand."; assert (0); if (ctx.view.rules().enabled(fix1373)) @@ -498,6 +498,9 @@ toStrandV2 ( } } + if (normPath.size() < 2) + return {temBAD_PATH, Strand{}}; + auto const strandSrc = normPath.front().getAccountID (); auto const strandDst = normPath.back().getAccountID (); bool const isDefaultPath = path.empty(); diff --git a/src/test/app/Flow_test.cpp b/src/test/app/Flow_test.cpp index af43983c27..22f6109625 100644 --- a/src/test/app/Flow_test.cpp +++ b/src/test/app/Flow_test.cpp @@ -1235,7 +1235,23 @@ struct Flow_test : public beast::unit_test::suite sendmax (drops(20000000000)), txflags (tfPartialPayment)); } + void + testEmptyStrand(std::initializer_list fs) + { + testcase("Empty Strand"); + using namespace jtx; + auto const alice = Account("alice"); + + Env env(*this, features(fs)); + + env.fund(XRP(10000), alice); + + env(pay(alice, alice, + alice["USD"](100)), + path(~alice["USD"]), + ter(temBAD_PATH)); + } void run() override { @@ -1269,6 +1285,7 @@ struct Flow_test : public beast::unit_test::suite testWithFeats(featureFlow); testWithFeats(featureFlow, fix1373); testWithFeats(featureFlow, fix1373, featureFlowCross); + testEmptyStrand({featureFlow, fix1373, featureFlowCross}); } };