From 65e9905a839ed1c9cf7ef50129056c0db75fba05 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 18 Jul 2017 12:31:57 +0200 Subject: [PATCH] Ensure valid address in basecoin init --- cmd/basecoin/commands/init.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/basecoin/commands/init.go b/cmd/basecoin/commands/init.go index b0b6a3fc28..26f4369662 100644 --- a/cmd/basecoin/commands/init.go +++ b/cmd/basecoin/commands/init.go @@ -1,11 +1,13 @@ package commands import ( + "encoding/hex" "fmt" "io/ioutil" "os" "path" + "github.com/pkg/errors" "github.com/spf13/cobra" tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" @@ -56,6 +58,14 @@ func initCmd(cmd *cobra.Command, args []string) error { return fmt.Errorf("`init` takes one argument, a basecoin account address. Generate one using `basecli keys new mykey`") } userAddr := args[0] + // verify this account is correct + data, err := hex.DecodeString(StripHex(userAddr)) + if err != nil { + return errors.Wrap(err, "Invalid address") + } + if len(data) != 20 { + return errors.New("Address must be 20-bytes in hex") + } // initalize basecoin genesisFile := cfg.GenesisFile()