diff options
author | Martin Holst Swende <martin@swende.se> | 2019-06-25 16:03:04 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-06-25 16:03:04 +0800 |
commit | 2ca89ea47902adcc0f7dab40e897c23265740fd7 (patch) | |
tree | ede7af5375598b3231c8ca4503a63256cfb7cd74 | |
parent | 1da5e0ebb0bf702f1e4d811b9dab9b3f4589e9e5 (diff) | |
download | go-tangerine-2ca89ea47902adcc0f7dab40e897c23265740fd7.tar go-tangerine-2ca89ea47902adcc0f7dab40e897c23265740fd7.tar.gz go-tangerine-2ca89ea47902adcc0f7dab40e897c23265740fd7.tar.bz2 go-tangerine-2ca89ea47902adcc0f7dab40e897c23265740fd7.tar.lz go-tangerine-2ca89ea47902adcc0f7dab40e897c23265740fd7.tar.xz go-tangerine-2ca89ea47902adcc0f7dab40e897c23265740fd7.tar.zst go-tangerine-2ca89ea47902adcc0f7dab40e897c23265740fd7.zip |
cmd/evm: evm input minor fixes (#19740)
* cmd/evm: evm input minor fixes, handle prefix, validate length, fixes #18041
* cmd/evm: remove whitespace
-rw-r--r-- | cmd/evm/runner.go | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/cmd/evm/runner.go b/cmd/evm/runner.go index 08f36dadc..318aa222a 100644 --- a/cmd/evm/runner.go +++ b/cmd/evm/runner.go @@ -17,7 +17,6 @@ package main import ( - "bytes" "encoding/json" "fmt" "io/ioutil" @@ -121,28 +120,36 @@ func runCmd(ctx *cli.Context) error { ret []byte err error ) + codeFileFlag := ctx.GlobalString(CodeFileFlag.Name) + codeFlag := ctx.GlobalString(CodeFlag.Name) + // The '--code' or '--codefile' flag overrides code in state - if ctx.GlobalString(CodeFileFlag.Name) != "" { + if codeFileFlag != "" || codeFlag != "" { var hexcode []byte - var err error - // If - is specified, it means that code comes from stdin - if ctx.GlobalString(CodeFileFlag.Name) == "-" { - //Try reading from stdin - if hexcode, err = ioutil.ReadAll(os.Stdin); err != nil { - fmt.Printf("Could not load code from stdin: %v\n", err) - os.Exit(1) + if codeFileFlag != "" { + var err error + // If - is specified, it means that code comes from stdin + if codeFileFlag == "-" { + //Try reading from stdin + if hexcode, err = ioutil.ReadAll(os.Stdin); err != nil { + fmt.Printf("Could not load code from stdin: %v\n", err) + os.Exit(1) + } + } else { + // Codefile with hex assembly + if hexcode, err = ioutil.ReadFile(codeFileFlag); err != nil { + fmt.Printf("Could not load code from file: %v\n", err) + os.Exit(1) + } } } else { - // Codefile with hex assembly - if hexcode, err = ioutil.ReadFile(ctx.GlobalString(CodeFileFlag.Name)); err != nil { - fmt.Printf("Could not load code from file: %v\n", err) - os.Exit(1) - } + hexcode = []byte(codeFlag) } - code = common.Hex2Bytes(string(bytes.TrimRight(hexcode, "\n"))) - - } else if ctx.GlobalString(CodeFlag.Name) != "" { - code = common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name)) + if len(hexcode)%2 != 0 { + fmt.Printf("Invalid input length for hex data (%d)\n", len(hexcode)) + os.Exit(1) + } + code = common.FromHex(string(hexcode)) } else if fn := ctx.Args().First(); len(fn) > 0 { // EASM-file to compile src, err := ioutil.ReadFile(fn) @@ -155,7 +162,6 @@ func runCmd(ctx *cli.Context) error { } code = common.Hex2Bytes(bin) } - initialGas := ctx.GlobalUint64(GasFlag.Name) if genesisConfig.GasLimit != 0 { initialGas = genesisConfig.GasLimit |