Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Kurtosis shell exec panics if stdin is not terminal (#686)
## Description: <!-- Describe this change, how it works, and the motivation behind it. --> Fixes a bug where if `os.Stdin` is not a terminal (for example, if you pipe a file) during `kurtosis service shell ...`, we call `terminal.Restore(stdinFd, oldState)` with `oldState` uninitialized. Repro steps: ```console $ kurtosis enclave add --name test-enclave $ kurtosis service add test-enclave test2 httpd --ports http=80 $ kurtosis service shell test-enclave test2 --exec "echo 1" < /dev/null ``` Causing the following error: ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x18a0854] goroutine 1 [running]: golang.org/x/term.restore(...) /go/pkg/mod/golang.org/x/term@v0.6.0/term_unix.go:57 golang.org/x/term.Restore(...) /go/pkg/mod/golang.org/x/term@v0.6.0/term.go:45 golang.org/x/crypto/ssh/terminal.Restore(0xc0001d1dd0?, 0x0?) /go/pkg/mod/golang.org/x/crypto@v0.7.0/ssh/terminal/terminal.go:64 +0x14 github.com/kurtosis-tech/kurtosis/cli/cli/commands/service/shell.run({0x20e01a0, 0xc00032a420}, {0x20f6388, 0xc000361420}, {0x1?, 0xa?}, {0xc0000cbaa0?, 0xc0000cba70?}, 0xc0000cbad0?, 0xc000360b60) /root/project/cli/cli/commands/service/shell/shell.go:147 +0x68a github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/highlevel/engine_consuming_kurtosis_command.(*EngineConsumingKurtosisCommand).getRunFunc.func1({0x20e01a0, 0xc00032a420}, 0x0?, 0xc000[13](https://github.com/victorcolombo/sei-chain/actions/runs/5201948897/jobs/9382840002?pr=1#step:8:14)9100?) /root/project/cli/cli/command_framework/highlevel/engine_consuming_kurtosis_command/engine_consuming_kurtosis_command.go:2[19](https://github.com/victorcolombo/sei-chain/actions/runs/5201948897/jobs/9382840002?pr=1#step:8:20) +0x224 github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel.(*LowlevelKurtosisCommand).MustGetCobraCommand.func2(0xc000334c00?, {0xc000139100, 0x2, 0x4}) /root/project/cli/cli/command_framework/lowlevel/lowlevel_kurtosis_command.go:294 +0x44e github.com/spf13/cobra.(*Command).execute(0xc000334c00, {0xc0001390c0, 0x4, 0x4}) /go/pkg/mod/github.com/spf13/cobra@v1.6.1-0.[20](https://github.com/victorcolombo/sei-chain/actions/runs/5201948897/jobs/9382840002?pr=1#step:8:21)230225[21](https://github.com/victorcolombo/sei-chain/actions/runs/5201948897/jobs/9382840002?pr=1#step:8:22)3037-567ea8ebc9b4/command.go:940 +0x862 github.com/spf13/cobra.(*Command).ExecuteC(0x30bc[22](https://github.com/victorcolombo/sei-chain/actions/runs/5201948897/jobs/9382840002?pr=1#step:8:23)0) /go/pkg/mod/github.com/spf13/cobra@v1.6.1-0.20[23](https://github.com/victorcolombo/sei-chain/actions/runs/5201948897/jobs/9382840002?pr=1#step:8:24)02[25](https://github.com/victorcolombo/sei-chain/actions/runs/5201948897/jobs/9382840002?pr=1#step:8:26)21[30](https://github.com/victorcolombo/sei-chain/actions/runs/5201948897/jobs/9382840002?pr=1#step:8:31)37-567ea8ebc9b4/command.go:1068 +0x3bd github.com/spf13/cobra.(*Command).Execute(...) /go/pkg/mod/github.com/spf13/cobra@v1.6.1-0.20230225213037-567ea8ebc9b4/command.go:992 main.main() /root/project/cli/cli/main.go:52 +0x7d ``` This is *blocking*, given that Github actions does not use a terminal as stdin: https://github.com/victorcolombo/sei-chain/actions/runs/5201948897/jobs/9382840002 ## Is this change user facing? NO <!-- If yes, please add the "user facing" label to the PR --> <!-- If yes, don't forget to include docs changes where relevant --> ## References (if applicable): <!-- Add relevant Github Issues, Discord threads, or other helpful information. -->
- Loading branch information