From e18aee5b4fa28ac09c06c7396f47b278b13a66ab Mon Sep 17 00:00:00 2001 From: stephen mcquay Date: Sun, 25 Feb 2018 09:42:48 -0800 Subject: [PATCH] Validate keyring input Linc helped me discover this bug by being into pushing buttons on my kc71 and watching the colors change. --- keyring/keyring.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/keyring/keyring.go b/keyring/keyring.go index a601a30..a138c70 100644 --- a/keyring/keyring.go +++ b/keyring/keyring.go @@ -15,6 +15,15 @@ import ( // NewKeyPair creates and adds a new OpenPGP keypair to an existing keyring. func NewKeyPair(root, name, email string) error { + if name == "" { + return errors.New("name cannot be empty") + } + if email == "" { + return errors.New("email cannot be empty") + } + if strings.ContainsAny(email, "()<>\x00") { + return fmt.Errorf("email %q contains invalid chars", email) + } if err := ensureDir(root); err != nil { return errors.Wrap(err, "can't find or create pgp dir") }