Skip to content

Commit

Permalink
blockchain: copy utxo status bytes to avoid UB
Browse files Browse the repository at this point in the history
It is undefined behavior if we directly use the value from a Get
call after the transaction has completed.
  • Loading branch information
Crypt-iQ committed Aug 6, 2024
1 parent b161cd6 commit 3eda1a5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion blockchain/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,14 @@ func dbPutUtxoStateConsistency(dbTx database.Tx, hash *chainhash.Hash) error {
// nothing was found.
func dbFetchUtxoStateConsistency(dbTx database.Tx) []byte {
// Fetch the serialized data from the database.
return dbTx.Metadata().Get(utxoStateConsistencyKeyName)
statusBytes := dbTx.Metadata().Get(utxoStateConsistencyKeyName)
if statusBytes != nil {
result := make([]byte, len(statusBytes))
copy(result, statusBytes)
return result
}

return nil
}

// createChainState initializes both the database and the chain state to the
Expand Down

0 comments on commit 3eda1a5

Please sign in to comment.