Skip to content

Commit 1e50bc2

Browse files
committed
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, ":".
1 parent 1bb68a2 commit 1e50bc2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

hack/.staticcheck_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ vendor/k8s.io/kubectl/pkg/cmd/config
103103
vendor/k8s.io/kubectl/pkg/cmd/edit
104104
vendor/k8s.io/kubectl/pkg/cmd/exec
105105
vendor/k8s.io/kubectl/pkg/cmd/get
106-
vendor/k8s.io/kubectl/pkg/cmd/proxy
107106
vendor/k8s.io/kubectl/pkg/cmd/rollingupdate
108107
vendor/k8s.io/kubectl/pkg/cmd/scale
109108
vendor/k8s.io/kubectl/pkg/cmd/set

staging/src/k8s.io/kubectl/pkg/cmd/proxy/proxy.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ func (o ProxyOptions) Validate() error {
200200
func (o ProxyOptions) RunProxy() error {
201201
server, err := proxy.NewServer(o.staticDir, o.apiPrefix, o.staticPrefix, o.filter, o.clientConfig, o.keepalive)
202202

203+
if err != nil {
204+
return err
205+
}
206+
203207
// Separate listening from serving so we can report the bound port
204208
// when it is chosen by os (eg: port == 0)
205209
var l net.Listener
@@ -209,9 +213,8 @@ func (o ProxyOptions) RunProxy() error {
209213
l, err = server.ListenUnix(o.unixSocket)
210214
}
211215
if err != nil {
212-
klog.Fatal(err)
216+
return err
213217
}
214218
fmt.Fprintf(o.IOStreams.Out, "Starting to serve on %s\n", l.Addr().String())
215-
klog.Fatal(server.ServeOnListener(l))
216-
return nil
219+
return server.ServeOnListener(l)
217220
}

0 commit comments

Comments
 (0)