From d3f6c4ef2d23d4eac9b32d188fa6ea8767b9a66c Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Tue, 14 Jun 2022 12:52:55 +0000 Subject: [PATCH] fix bug in iouescrow, hook macro --- hook/examples/macro.h | 2 +- src/ripple/app/tx/impl/Escrow.cpp | 9 +++++++++ src/ripple/ledger/View.h | 7 +++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/hook/examples/macro.h b/hook/examples/macro.h index 2163a4bf9..763e8621e 100644 --- a/hook/examples/macro.h +++ b/hook/examples/macro.h @@ -224,7 +224,7 @@ int out_len = 0;\ #define INT64_FROM_BUF(buf)\ - ((((uint64_t)((buf)[0]&7FU) << 56) +\ + ((((uint64_t)((buf)[0] & 0x7FU) << 56) +\ ((uint64_t)((buf)[1]) << 48) +\ ((uint64_t)((buf)[2]) << 40) +\ ((uint64_t)((buf)[3]) << 32) +\ diff --git a/src/ripple/app/tx/impl/Escrow.cpp b/src/ripple/app/tx/impl/Escrow.cpp index 56eeb1c7b..25ba80726 100644 --- a/src/ripple/app/tx/impl/Escrow.cpp +++ b/src/ripple/app/tx/impl/Escrow.cpp @@ -261,6 +261,15 @@ EscrowCreate::doApply() // perform the lock as a dry run before // we modify anything on-ledger sleLine = ctx_.view().peek(keylet::line(account, amount.getIssuer(), amount.getCurrency())); + if (!sleLine) + { + JLOG(ctx_.journal.trace()) + << "EscrowCreate::doApply trustAdjustLockedBalance trustline missing " + << account << "-" + << amount.getIssuer() << "/" + << amount.getCurrency(); + return tecUNFUNDED; + } { TER result = diff --git a/src/ripple/ledger/View.h b/src/ripple/ledger/View.h index 2b97b2d61..2530ed333 100644 --- a/src/ripple/ledger/View.h +++ b/src/ripple/ledger/View.h @@ -494,6 +494,9 @@ trustAdjustLockedBalance( if (!view.rules().enabled(featurePaychanAndEscrowForTokens)) return tefINTERNAL; + if (!sleLine) + return tecINTERNAL; + auto const currency = deltaAmt.getCurrency(); auto const issuer = deltaAmt.getIssuer(); @@ -989,12 +992,12 @@ trustTransferLockedBalance( STAmount priorBalance = dstHigh ? -((*sleDstLine)[sfBalance]) : (*sleDstLine)[sfBalance]; - STAmount finalBalance = priorBalance + (flipDstAmt ? -dstAmt : dstAmt); + STAmount finalBalance = priorBalance + dstAmt; if (finalBalance < priorBalance) { JLOG(j.warn()) - << "trustTransferLockedBalance resulted in a lower final balance on dest line"; + << "trustTransferLockedBalance resulted in a lower/equal final balance on dest line"; return tecINTERNAL; }