Skip to content

Commit

Permalink
qt: Avoid invalid memory access in decomposeTransaction()
Browse files Browse the repository at this point in the history
  • Loading branch information
lateminer committed Nov 2, 2023
1 parent 7a5136b commit a161a80
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,31 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
CAmount nCredit = wtx.credit;
CAmount nDebit = wtx.debit;
CAmount nNet = nCredit - nDebit;
uint256 hash = wtx.tx->GetHash(), hashPrev;
uint256 hash = wtx.tx->GetHash();
std::map<std::string, std::string> mapValue = wtx.value_map;

if (nNet > 0 || wtx.is_coinbase || wtx.is_coinstake)
{
//
// Credit
//
CAmount nReward = -nDebit;
for(unsigned int j = 0; j < wtx.tx->vout.size(); j++)
{
if (wtx.tx->vout[j].scriptPubKey == wtx.tx->vout[1].scriptPubKey)
nReward += wtx.tx->vout[j].nValue;
}

for(unsigned int i = 0; i < wtx.tx->vout.size(); i++)
{
const CTxOut& txout = wtx.tx->vout[i];
isminetype mine = wtx.txout_is_mine[i];
if(mine)
{
TransactionRecord sub(hash, nTime);
sub.idx = i; // vout index
sub.credit = txout.nValue;
if (wtx.is_coinstake) // Combine into single output for coinstake
{
sub.idx = 1; // vout index
sub.credit = nNet;
}
else
{
sub.idx = i; // vout index
sub.credit = txout.nValue;
}
sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY;
if (wtx.txout_address_is_mine[i])
{
Expand All @@ -76,18 +77,16 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
// Generated
sub.type = TransactionRecord::Generated;
}
if (wtx.is_coinstake)
else if (wtx.is_coinstake)
{
// Generated
// Staked
sub.type = TransactionRecord::Staked;

if (hashPrev == hash)
continue; // last coinstake output
sub.credit = nReward;
hashPrev = hash;
}

parts.append(sub);

if (wtx.is_coinstake)
break; // Single output for coinstake
}
}
}
Expand Down

0 comments on commit a161a80

Please sign in to comment.