diff options
author | Elias Naur <elias.naur@gmail.com> | 2017-07-17 20:25:46 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-07-17 20:25:46 +0800 |
commit | 23c6fcdbe834b70ff25473e6ff03da94814609c1 (patch) | |
tree | 09eaf858707d61ff2f117cadc0e11e2a0e77f0da /mobile/types.go | |
parent | cf5d4b55412f570bd1b492998b0c0b8e953e2418 (diff) | |
download | dexon-23c6fcdbe834b70ff25473e6ff03da94814609c1.tar.gz dexon-23c6fcdbe834b70ff25473e6ff03da94814609c1.tar.zst dexon-23c6fcdbe834b70ff25473e6ff03da94814609c1.zip |
mobile: don't retain transient []byte in CallMsg.SetData (#14804)
* mobile: don't retain transient []byte in CallMsg.SetData
Go mobile doesn't copy []byte parameters, for performance and to allow
writes to the byte array be reflected in the native byte array.
Unfortunately, that means []byte arguments are only valid during the
call it is being passed into.
CallMsg.SetData retains such a byte array. Copy it instead
Fixes #14675
* mobile: copy all []byte arguments from gomobile
To avoid subtle errors when accidentially retaining an otherwise
transient byte slice coming from gomobile, copy all byte slices before
use.
* mobile: replace copySlice with common.CopyBytes
Diffstat (limited to 'mobile/types.go')
-rw-r--r-- | mobile/types.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/mobile/types.go b/mobile/types.go index 4c4cd8822..088c7c6b3 100644 --- a/mobile/types.go +++ b/mobile/types.go @@ -23,6 +23,7 @@ import ( "errors" "fmt" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rlp" ) @@ -68,7 +69,7 @@ func NewHeaderFromRLP(data []byte) (*Header, error) { h := &Header{ header: new(types.Header), } - if err := rlp.DecodeBytes(data, h.header); err != nil { + if err := rlp.DecodeBytes(common.CopyBytes(data), h.header); err != nil { return nil, err } return h, nil @@ -145,7 +146,7 @@ func NewBlockFromRLP(data []byte) (*Block, error) { b := &Block{ block: new(types.Block), } - if err := rlp.DecodeBytes(data, b.block); err != nil { + if err := rlp.DecodeBytes(common.CopyBytes(data), b.block); err != nil { return nil, err } return b, nil @@ -212,7 +213,7 @@ type Transaction struct { // NewTransaction creates a new transaction with the given properties. func NewTransaction(nonce int64, to *Address, amount, gasLimit, gasPrice *BigInt, data []byte) *Transaction { - return &Transaction{types.NewTransaction(uint64(nonce), to.address, amount.bigint, gasLimit.bigint, gasPrice.bigint, data)} + return &Transaction{types.NewTransaction(uint64(nonce), to.address, amount.bigint, gasLimit.bigint, gasPrice.bigint, common.CopyBytes(data))} } // NewTransactionFromRLP parses a transaction from an RLP data dump. @@ -220,7 +221,7 @@ func NewTransactionFromRLP(data []byte) (*Transaction, error) { tx := &Transaction{ tx: new(types.Transaction), } - if err := rlp.DecodeBytes(data, tx.tx); err != nil { + if err := rlp.DecodeBytes(common.CopyBytes(data), tx.tx); err != nil { return nil, err } return tx, nil @@ -285,7 +286,7 @@ func (tx *Transaction) WithSignature(sig []byte, chainID *BigInt) (signedTx *Tra if chainID != nil { signer = types.NewEIP155Signer(chainID.bigint) } - rawTx, err := tx.tx.WithSignature(signer, sig) + rawTx, err := tx.tx.WithSignature(signer, common.CopyBytes(sig)) return &Transaction{rawTx}, err } @@ -315,7 +316,7 @@ func NewReceiptFromRLP(data []byte) (*Receipt, error) { r := &Receipt{ receipt: new(types.Receipt), } - if err := rlp.DecodeBytes(data, r.receipt); err != nil { + if err := rlp.DecodeBytes(common.CopyBytes(data), r.receipt); err != nil { return nil, err } return r, nil |