From 41c4e965c353187889f9b86c3e541b775656dc18 Mon Sep 17 00:00:00 2001 From: Zihong Zheng Date: Thu, 25 May 2017 10:26:51 -0700 Subject: [PATCH] Fix potential nil pointer dereference for kube-proxy healthcheck --- pkg/proxy/healthcheck/healthcheck.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/proxy/healthcheck/healthcheck.go b/pkg/proxy/healthcheck/healthcheck.go index c7187a6908f..39f10f71a26 100644 --- a/pkg/proxy/healthcheck/healthcheck.go +++ b/pkg/proxy/healthcheck/healthcheck.go @@ -197,7 +197,13 @@ var _ http.Handler = hcHandler{} func (h hcHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { h.hcs.lock.Lock() - count := h.hcs.services[h.name].endpoints + svc, ok := h.hcs.services[h.name] + if !ok || svc == nil { + h.hcs.lock.Unlock() + glog.Errorf("Received request for closed healthcheck %q", h.name.String()) + return + } + count := svc.endpoints h.hcs.lock.Unlock() resp.Header().Set("Content-Type", "application/json")