From 1e50bc2d094410f3848b4dbc5f0442440d8f7d77 Mon Sep 17 00:00:00 2001 From: Odin Ugedal Date: Fri, 26 Jul 2019 20:06:46 +0200 Subject: [PATCH] Add error check in kubectl proxy on server setup If "NewServer" returns an error, it will result in a nil pointer dereference segfault. A simple way to test the behavior is to prefix the server url with a colon, ":". --- hack/.staticcheck_failures | 1 - staging/src/k8s.io/kubectl/pkg/cmd/proxy/proxy.go | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hack/.staticcheck_failures b/hack/.staticcheck_failures index cc2798e5b42..f15c8b00ee5 100644 --- a/hack/.staticcheck_failures +++ b/hack/.staticcheck_failures @@ -103,7 +103,6 @@ vendor/k8s.io/kubectl/pkg/cmd/config vendor/k8s.io/kubectl/pkg/cmd/edit vendor/k8s.io/kubectl/pkg/cmd/exec vendor/k8s.io/kubectl/pkg/cmd/get -vendor/k8s.io/kubectl/pkg/cmd/proxy vendor/k8s.io/kubectl/pkg/cmd/rollingupdate vendor/k8s.io/kubectl/pkg/cmd/scale vendor/k8s.io/kubectl/pkg/cmd/set diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/proxy/proxy.go b/staging/src/k8s.io/kubectl/pkg/cmd/proxy/proxy.go index 904ab782b0f..98ed1405f3d 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/proxy/proxy.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/proxy/proxy.go @@ -200,6 +200,10 @@ func (o ProxyOptions) Validate() error { func (o ProxyOptions) RunProxy() error { server, err := proxy.NewServer(o.staticDir, o.apiPrefix, o.staticPrefix, o.filter, o.clientConfig, o.keepalive) + if err != nil { + return err + } + // Separate listening from serving so we can report the bound port // when it is chosen by os (eg: port == 0) var l net.Listener @@ -209,9 +213,8 @@ func (o ProxyOptions) RunProxy() error { l, err = server.ListenUnix(o.unixSocket) } if err != nil { - klog.Fatal(err) + return err } fmt.Fprintf(o.IOStreams.Out, "Starting to serve on %s\n", l.Addr().String()) - klog.Fatal(server.ServeOnListener(l)) - return nil + return server.ServeOnListener(l) }