From f65c9ad40f2f5cdc581bdaf72e7dc68e9d7f7a80 Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Thu, 19 Mar 2020 14:57:02 +0200 Subject: Check for overflow when calculating sum of outputs --- src/primitives/transaction.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/primitives') diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 28c145f71d..6e72c1f15c 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -9,6 +9,8 @@ #include #include +#include + std::string COutPoint::ToString() const { return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n); @@ -84,10 +86,11 @@ CAmount CTransaction::GetValueOut() const { CAmount nValueOut = 0; for (const auto& tx_out : vout) { - nValueOut += tx_out.nValue; - if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut)) + if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut + tx_out.nValue)) throw std::runtime_error(std::string(__func__) + ": value out of range"); + nValueOut += tx_out.nValue; } + assert(MoneyRange(nValueOut)); return nValueOut; } -- cgit v1.2.3