Skip to content

Commit 1968ac0

Browse files
authored
Merge pull request #2618 from CortexFoundation/dev
core/vm: avoid escape to heap
2 parents 76d59d4 + ca6857a commit 1968ac0

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

core/vm/contracts.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,13 @@ func (c *ecrecover) Run(input []byte) ([]byte, error) {
271271
if bitutil.TestBytes(input[32:63]) || !crypto.ValidateSignatureValues(v, r, s, false) {
272272
return nil, nil
273273
}
274-
sig := make([]byte, 65)
275-
copy(sig, input[64:128])
274+
// We must make sure not to modify the 'input', so placing the 'v' along with
275+
// the signature needs to be done on a new allocation
276+
var sig [65]byte
277+
copy(sig[:], input[64:128])
276278
sig[64] = v
277279
// v needs to be at the end for libsecp256k1
278-
pubKey, err := crypto.Ecrecover(input[:32], sig)
280+
pubKey, err := crypto.Ecrecover(input[:32], sig[:])
279281
// make sure the public key is a valid one
280282
if err != nil {
281283
return nil, nil

0 commit comments

Comments
 (0)