antoniomika / sish

HTTP(S)/WS(S)/TCP Tunnels to localhost using only SSH.
https://ssi.sh
MIT License
4.02k stars 308 forks source link

Crash during start when directory not exists #316

Closed condemil closed 3 months ago

condemil commented 3 months ago

sish crashes when any of the directories, that was provided through command arguments, doesn't exist. The best solution would be to create the non-existing directories instead of crash.

Example of the crash error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xb2c04a]

goroutine 1 [running]:
github.com/antoniomika/sish/utils.loadKeys.func2({0x7ffe8693df77, 0xd}, {0x0, 0x0}, {0xe28c20, 0xc0003ff020})
        /app/utils/utils.go:420 +0x4a
path/filepath.WalkDir({0x7ffe8693df77, 0xd}, 0xc00029fa48)
        /usr/local/go/src/path/filepath/path.go:531 +0x9c
github.com/antoniomika/sish/utils.loadKeys()
        /app/utils/utils.go:419 +0xad
github.com/antoniomika/sish/utils.WatchKeys()
        /app/utils/utils.go:351 +0x17
github.com/antoniomika/sish/sshmuxer.Start()
        /app/sshmuxer/sshmuxer.go:70 +0x3d4
github.com/antoniomika/sish/cmd.runCommand(0xc000163d00?, {0xce2f87?, 0x7?, 0xcd9971?})
        /app/cmd/sish.go:229 +0xf
github.com/spf13/cobra.(*Command).execute(0x16e2560, {0xc000034110, 0x3, 0x3})
        /go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:987 +0xab1
github.com/spf13/cobra.(*Command).ExecuteC(0x16e2560)
        /go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
        /go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/antoniomika/sish/cmd.Execute(...)
        /app/cmd/sish.go:224
main.main()
        /app/main.go:12 +0x1f
antoniomika commented 3 months ago

This is intentional (program exits if the directories don't exist). We can do better at making the error more clear though! I'll add a task to the backlog for it.