From c7d4cad3815013feeaf1829de916b8b604a5d4e6 Mon Sep 17 00:00:00 2001 From: Linus789 Date: Wed, 22 Feb 2023 10:13:16 +0100 Subject: [PATCH] validate -user argument for correctness --- install.go | 9 +++++++++ uninstall.go | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/install.go b/install.go index a361226..91d62a3 100644 --- a/install.go +++ b/install.go @@ -46,6 +46,15 @@ func runInstall(args []string) error { if *installUpdatesExclude != "" && !*installUpdates { return fmt.Errorf("-e can only be used for upgrading (i.e. -u)") } + if *installUser != "" && *installUser != "all" && *installUser != "current" { + n, err := strconv.Atoi(*installUser) + if err != nil { + return fmt.Errorf("-user has to be ") + } + if n < 0 { + return fmt.Errorf("-user cannot have a negative number as USER_ID") + } + } device, err := oneDevice() if err != nil { return err diff --git a/uninstall.go b/uninstall.go index f81f3af..ebbb66f 100644 --- a/uninstall.go +++ b/uninstall.go @@ -26,6 +26,15 @@ func runUninstall(args []string) error { if len(args) < 1 { return fmt.Errorf("no package names given") } + if *uninstallUser != "all" && *uninstallUser != "current" { + n, err := strconv.Atoi(*uninstallUser) + if err != nil { + return fmt.Errorf("-user has to be ") + } + if n < 0 { + return fmt.Errorf("-user cannot have a negative number as USER_ID") + } + } device, err := oneDevice() if err != nil { return err