From 360cc86ce5cb1d3040a886a864c905b153dc0eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=A2=93=E9=93=AD?= <83150084+NgZiming@users.noreply.github.com> Date: Fri, 24 Jun 2022 22:09:40 +0800 Subject: [PATCH] fix: panic when environment variables are empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On mac OS, environment variables like: OLDPWD are usually empty. May trigger panics like: ```bash 😄 minikube v1.26.0 on Darwin 11.6.5 panic: runtime error: index out of range [1] with length 1 goroutine 1 [running]: k8s.io/minikube/cmd/minikube/cmd.displayEnviron({0xc000a69a40?, 0x1c, 0xb?}) /private/tmp/minikube-20220623-65769-c2xa25/cmd/minikube/cmd/start.go:445 +0x252 k8s.io/minikube/cmd/minikube/cmd.runStart(0x7316040?, {0x5d07e13?, 0x0?, 0x0?}) /private/tmp/minikube-20220623-65769-c2xa25/cmd/minikube/cmd/start.go:157 +0x245 github.com/spf13/cobra.(*Command).execute(0x7316040, {0x73736d8, 0x0, 0x0}) /Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:876 +0x67b github.com/spf13/cobra.(*Command).ExecuteC(0x7313fc0) /Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:990 +0x3b4 github.com/spf13/cobra.(*Command).Execute(...) /Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:918 k8s.io/minikube/cmd/minikube/cmd.Execute() /private/tmp/minikube-20220623-65769-c2xa25/cmd/minikube/cmd/root.go:170 +0xca5 main.main() /private/tmp/minikube-20220623-65769-c2xa25/cmd/minikube/main.go:88 +0x255 ``` --- cmd/minikube/cmd/start.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 96dd95bb84c0..3a9f6ca313c8 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -441,6 +441,9 @@ func displayVersion(version string) { func displayEnviron(env []string) { for _, kv := range env { bits := strings.SplitN(kv, "=", 2) + if len(bits) < 2 { + continue + } k := bits[0] v := bits[1] if strings.HasPrefix(k, "MINIKUBE_") || k == constants.KubeconfigEnvVar {