From e064ec40de3773cc8225e98dfa73553e992cba78 Mon Sep 17 00:00:00 2001 From: lash Date: Wed, 26 Mar 2025 18:28:06 +0000 Subject: [PATCH] Check argument count in devtools admin --- internal/cmd/cmd.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 2fa0477..5c550ea 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -13,6 +13,11 @@ import ( "git.grassecon.net/grassrootseconomics/visedriver/storage" ) +var argc map[string]int = map[string]int{ + "reset": 0, + "admin": 1, +} + var ( logg = logging.NewVanilla().WithDomain("cmd").WithContextKey("SessionId") ) @@ -153,12 +158,23 @@ func (c *Cmd) parseCmdReset(cmd string, param string, more []string) (bool, erro } func (c *Cmd) Parse(args []string) error { - if len(args) < 2 { + var param string + if len(args) < 1 { return fmt.Errorf("Wrong number of arguments: %v", args) } cmd := args[0] - param := args[1] - args = args[2:] + + n, ok := argc[cmd] + if !ok { + return fmt.Errorf("invalid command: %v", cmd) + } + if n > 0 { + if len(args) < n + 1 { + return fmt.Errorf("Wrong number of arguments, need: %d", n) + } + param = args[1] + args = args[2:] + } r, err := c.parseCmdAdmin(cmd, param, args) if err != nil {