Merge pull request #4302 from wpaulino/btcwallet-fetchinputinfo-bounds-check

btcwallet: add transaction outputs bounds check to FetchInputInfo
This commit is contained in:
Olaoluwa Osuntokun 2020-05-21 17:22:25 -07:00 committed by GitHub
commit 53da66a6fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -37,6 +37,11 @@ func (b *BtcWallet) FetchInputInfo(prevOut *wire.OutPoint) (*lnwallet.Utxo, erro
// we actually have control of this output. We do this because the check // we actually have control of this output. We do this because the check
// above only guarantees that the transaction is somehow relevant to us, // above only guarantees that the transaction is somehow relevant to us,
// like in the event of us being the sender of the transaction. // like in the event of us being the sender of the transaction.
numOutputs := uint32(len(txDetail.TxRecord.MsgTx.TxOut))
if prevOut.Index >= numOutputs {
return nil, fmt.Errorf("invalid output index %v for "+
"transaction with %v outputs", prevOut.Index, numOutputs)
}
pkScript := txDetail.TxRecord.MsgTx.TxOut[prevOut.Index].PkScript pkScript := txDetail.TxRecord.MsgTx.TxOut[prevOut.Index].PkScript
if _, err := b.fetchOutputAddr(pkScript); err != nil { if _, err := b.fetchOutputAddr(pkScript); err != nil {
return nil, err return nil, err