validate signature size on SendTransactionWithSignature (#1401)

* chekc signature size to avoid panic from go-ethereum

* add comment and constant

* add test
This commit is contained in:
Andrea Franz 2019-03-01 14:49:30 +01:00 committed by GitHub
parent cf8f20b23c
commit b3e2cb2965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package transactions
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"fmt" "fmt"
"math/big" "math/big"
"sync" "sync"
@ -24,8 +25,13 @@ const (
sendTxTimeout = 300 * time.Second sendTxTimeout = 300 * time.Second
defaultGas = 90000 defaultGas = 90000
validSignatureSize = 65
) )
// ErrInvalidSignatureSize is returned if a signature is not 65 bytes to avoid panic from go-ethereum
var ErrInvalidSignatureSize = errors.New("signature size must be 65")
type ErrBadNonce struct { type ErrBadNonce struct {
nonce uint64 nonce uint64
expectedNonce uint64 expectedNonce uint64
@ -88,6 +94,10 @@ func (t *Transactor) SendTransactionWithSignature(args SendTxArgs, sig []byte) (
return hash, ErrInvalidSendTxArgs return hash, ErrInvalidSendTxArgs
} }
if len(sig) != validSignatureSize {
return hash, ErrInvalidSignatureSize
}
chainID := big.NewInt(int64(t.networkID)) chainID := big.NewInt(int64(t.networkID))
signer := types.NewEIP155Signer(chainID) signer := types.NewEIP155Signer(chainID)

View File

@ -374,6 +374,12 @@ func (s *TransactorSuite) TestSendTransactionWithSignature() {
} }
} }
func (s *TransactorSuite) TestSendTransactionWithSignature_InvalidSignature() {
args := SendTxArgs{}
_, err := s.manager.SendTransactionWithSignature(args, []byte{})
s.Equal(ErrInvalidSignatureSize, err)
}
func (s *TransactorSuite) TestHashTransaction() { func (s *TransactorSuite) TestHashTransaction() {
privKey, err := crypto.GenerateKey() privKey, err := crypto.GenerateKey()
s.Require().NoError(err) s.Require().NoError(err)