canonical / lxd

Powerful system container and virtual machine manager
https://canonical.com/lxd
GNU Affero General Public License v3.0
4.27k stars 910 forks source link

`lxc remote add target ''` causes a panic #13682

Open simondeziel opened 2 days ago

simondeziel commented 2 days ago

lxc will panic if the expected token is an empty string:

$ lxc remote add target '' 
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.(*cmdRemoteAdd).run(0xc000201ce0, 0xc0001b19c8?, {0xc00020d4c0, 0x2, 0x0?})
    github.com/canonical/lxd/lxc/remote.go:352 +0x2cb9
github.com/spf13/cobra.(*Command).execute(0xc0002dc308, {0xc00020d4a0, 0x2, 0x2})
    github.com/spf13/cobra@v1.8.1/command.go:985 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc0001faf08)
    github.com/spf13/cobra@v1.8.1/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
    github.com/spf13/cobra@v1.8.1/command.go:1041
main.main()
    github.com/canonical/lxd/lxc/main.go:289 +0x1c13

While it is obviously being feed bogus data (`` isn't a valid token), panicking isn't a nice failure mode.