From 23c6fcdbe834b70ff25473e6ff03da94814609c1 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 17 Jul 2017 14:25:46 +0200 Subject: 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 --- mobile/common.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mobile/common.go') diff --git a/mobile/common.go b/mobile/common.go index 3090014c5..047d8e1f6 100644 --- a/mobile/common.go +++ b/mobile/common.go @@ -35,7 +35,7 @@ type Hash struct { // NewHashFromBytes converts a slice of bytes to a hash value. func NewHashFromBytes(binary []byte) (hash *Hash, _ error) { h := new(Hash) - if err := h.SetBytes(binary); err != nil { + if err := h.SetBytes(common.CopyBytes(binary)); err != nil { return nil, err } return h, nil @@ -136,7 +136,7 @@ type Address struct { // NewAddressFromBytes converts a slice of bytes to a hash value. func NewAddressFromBytes(binary []byte) (address *Address, _ error) { a := new(Address) - if err := a.SetBytes(binary); err != nil { + if err := a.SetBytes(common.CopyBytes(binary)); err != nil { return nil, err } return a, nil -- cgit v1.2.3