pressly / sup

Super simple deployment tool - think of it like 'make' for a network of servers
https://pressly.github.io/sup
MIT License
2.48k stars 178 forks source link

Error "panic: runtime error: slice bounds out of range" when using option --sshconfig #136

Closed hth2 closed 6 years ago

hth2 commented 6 years ago

Hello,

when I tried the --sshconfig option I got an error as below:

$ sup --sshconfig=~/.ssh/config vps ping     
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
main.resolvePath(0x0, 0x0, 0xc4200165b0, 0xc)
    /Users/vojtechvitek/go/src/github.com/pressly/sup/cmd/sup/main.go:191 +0x105
main.main()
    /Users/vojtechvitek/go/src/github.com/pressly/sup/cmd/sup/main.go:304 +0xd1d

Am I missing something, or this is a bug?

btw, sup --help show this:

  -sshconfig string
        Read SSH Config file, ie. ~/.ssh/config file

Note that there are only 1 hyphen. I tried with both 1 & 2 hyphens and the result is the same.

palvarezcordoba commented 6 years ago

Write what release/commit are you using.

hth2 commented 6 years ago

edit: I downloaded https://github.com/pressly/sup/releases/download/v0.5.1/sup-linux64

Currently it is:

$ sup -v
0.5
palvarezcordoba commented 6 years ago

At line 284 there is: confHosts, err := sshconfig.ParseSSHConfig(resolvePath(sshConfig)) confHosts will be of type []*SSHHost, as we can see here if there is not IdentityFile on ssh config file, it will not be initialitated, so, at line 304 when the program calls to resolvePath() passing conf.IdentityFile as argument; there is a panic at 191, because we are doing: if path[:2] == "~/" { That is a error, because the length of path will be 0.

@VojtechVitek see that.

palvarezcordoba commented 6 years ago

@hanthethanh you could try to go to append at the beginning of the function resolvePath and add: if len(path) == 0 { return "" } or: if path == "" { return "" }

It should work, I guess. I can not ensure it; this is my first day watching this project and I have no idea. xD

hth2 commented 6 years ago

thank you, it works now.

VojtechVitek commented 6 years ago

Thanks for the fix @palvarezcordoba 👍