1
0
mirror of https://github.com/google/gops.git synced 2024-11-24 08:22:25 +02:00

fix out of bounds panic

This commit is contained in:
JBD 2018-07-11 12:14:45 -07:00
parent 60aa68d3cc
commit 89672dbe3c
2 changed files with 5 additions and 1 deletions

2
cmd.go
View File

@ -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

View File

@ -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)