blockchain: copy utxo status bytes to avoid UB

It is undefined behavior if we directly use the value from a Get
call after the transaction has completed.
This commit is contained in:
Eugene Siegel 2024-08-06 11:49:23 -04:00
parent b161cd6a19
commit 3eda1a58a2
No known key found for this signature in database
GPG Key ID: 118759E83439A9B1

View File

@ -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