From 230c69b438e553c45f6f19a3c8d97f4f717d2099 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Mon, 22 Oct 2018 17:13:36 -0700 Subject: [PATCH] Validate threshold rather than letting it panic --- client/keys/show.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/client/keys/show.go b/client/keys/show.go index 6159b0920..fe8641831 100644 --- a/client/keys/show.go +++ b/client/keys/show.go @@ -72,7 +72,13 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) { } pks[i] = info.GetPubKey() } - multikey := multisig.NewPubKeyMultisigThreshold(viper.GetInt(flagMultiSigThreshold), pks) + + multisigThreshold := viper.GetInt(flagMultiSigThreshold) + err = validateMultisigThreshold(multisigThreshold, len(args)) + if err != nil { + return err + } + multikey := multisig.NewPubKeyMultisigThreshold(multisigThreshold, pks) info = multiSigKey{ name: "multi", key: multikey, @@ -108,6 +114,17 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) { return nil } +func validateMultisigThreshold(k, nKeys int) error { + if k <= 0 { + return fmt.Errorf("threshold must be a positive integer") + } + if nKeys < k { + return fmt.Errorf( + "threshold k of n multisignature: %d < %d", nKeys, k) + } + return nil +} + func getBechKeyOut(bechPrefix string) (bechKeyOutFn, error) { switch bechPrefix { case "acc":