From 89672dbe3c4ba97d53af7e839e8097e1ccbb4977 Mon Sep 17 00:00:00 2001 From: JBD Date: Wed, 11 Jul 2018 12:14:45 -0700 Subject: [PATCH] fix out of bounds panic --- cmd.go | 2 +- main.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd.go b/cmd.go index 1bcd346..a59449e 100644 --- a/cmd.go +++ b/cmd.go @@ -185,7 +185,7 @@ func targetToAddr(target string) (*net.TCPAddr, error) { } port, err := internal.GetPort(pid) if err != nil { - return nil, fmt.Errorf("couldn't get port for PID %s: %v", pid, err) + return nil, fmt.Errorf("couldn't get port for PID %v: %v", pid, err) } addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:"+port) return addr, nil diff --git a/main.go b/main.go index 1b78dac..867ae4b 100644 --- a/main.go +++ b/main.go @@ -72,6 +72,10 @@ func main() { if !ok { usage("unknown subcommand") } + if len(os.Args) < 3 { + usage("Missing PID or address.") + os.Exit(1) + } addr, err := targetToAddr(os.Args[2]) if err != nil { fmt.Fprintf(os.Stderr, "Couldn't resolve addr or pid %v to TCPAddress: %v\n", os.Args[2], err)