xeth: added address hex check and length check
This commit is contained in:
11
xeth/xeth.go
11
xeth/xeth.go
@ -20,8 +20,10 @@ package xeth
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -45,6 +47,7 @@ var (
|
||||
defaultGasPrice = big.NewInt(10000000000000) //150000000000
|
||||
defaultGas = big.NewInt(90000) //500000
|
||||
dappStorePre = []byte("dapp-")
|
||||
addrReg = regexp.MustCompile(`^(0x)?[a-fA-F0-9]{40}$`)
|
||||
)
|
||||
|
||||
// byte will be inferred
|
||||
@ -878,6 +881,10 @@ func (self *XEth) Sign(fromStr, hashStr string, didUnlock bool) (string, error)
|
||||
return common.ToHex(sig), nil
|
||||
}
|
||||
|
||||
func isAddress(addr string) bool {
|
||||
return addrReg.MatchString(addr)
|
||||
}
|
||||
|
||||
func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
|
||||
|
||||
// this minimalistic recoding is enough (works for natspec.js)
|
||||
@ -887,6 +894,10 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS
|
||||
return "", err
|
||||
}
|
||||
|
||||
if !isAddress(toStr) {
|
||||
return "", errors.New("Invalid address")
|
||||
}
|
||||
|
||||
var (
|
||||
from = common.HexToAddress(fromStr)
|
||||
to = common.HexToAddress(toStr)
|
||||
|
Reference in New Issue
Block a user